[Csnd] csound segfaults on numeric pfield when expecting string argument

Hi everyone, I’ve gotten csound6~ in Max handling events with strings in them nicely now, so that I can dynamically create control processes that write to kchannels. However, if one sends a numeric pfield to an instrument that is expecting a string pfield, it segfaults. The other way around is handled gracefully: if I send a string arg to a regular instrument where it expects a number, I get a NaN out and no crash.

This is a bit of a show stopper for my use case, as I want to make sure there is no chance of tanking Max from an illformed input score event. If need be I’m willing to dive into the main source to fix it, but wanted to float this here first to find out if there are workarounds, or what the protocol for fixing something like this should be (as I have never contributed to core).

My example csd is attached

thanks
iain

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

cs-out-msg.csd (862 Bytes)

I’d say open a ticket and we can look at it. Ideally we would like an example of the fault that can be reproduced with a simple CSD running straight into Csound (i.e. not specific to a given host or frontend).

Prof. Victor Lazzarini
Maynooth University
Ireland

cs-out-msg.csd (914 Bytes)

btw, looking at your CSD the issue seems to be with strget.

Prof. Victor Lazzarini
Maynooth University
Ireland

cs-out-msg.csd (914 Bytes)

I am not at a computer now, but looking at strget, it should return an empty string if given a numeric argument that does not correspond to a strset string index. So that is something to check first; if it’s an empty string then it’s predicted behaviour.

Then attention should turn to chnset, to see if it is crashing on an empty channel name.

Prof. Victor Lazzarini
Maynooth University
Ireland

cs-out-msg.csd (914 Bytes)

Hi Victor, thanks for answering these. I have attached a testing csd. You are correct, it is chnset crashing on an empty string. This happens if I pass an empty string as an arg, or through a pfield using strget, or by having the empty string come from the number.

Is there an alternative way to safely get a string from a pfield that will not result in an empty string? (ie, it could become “99” for the channel name or something, which would hopefully not crash?)

And for opening a ticket, is that on github, or?

thanks
iain

string-chan-bug.csd (679 Bytes)

sorry, forgot to mention I used the test csd with command line csound outside of Max.

iain

Try this:

instr xx

  S_chan strget p4
  if strlen(S_chan) == 0 then
    prints "Not a string\n"
    turnoff

  endif
  klfo lfo 1, 1
  chnset klfo, S_chan
endin


Csound mailing list Send bugs reports to Discussions of bugs and features can be posted here

chnget should nor crash, so that needs to be fixed. We can’t change the behaviour of strget, I’m afraid.

You can use strcmp to check for an empty string to avoid the crash for now.

Prof. Victor Lazzarini
Maynooth University
Ireland

string-chan-bug.csd (723 Bytes)

yes, crashing is ugly.

Prof. Victor Lazzarini
Maynooth University
Ireland

Ok, this is done now. It was only chnset that needed fixing, chnget was fine. In csound6 branch. I did not apply changes yet to develop,
because that whole area needs reviewing anyway.

commit 512984db5dbb637fc53b3a50ff8480dbf715d6a1 (HEAD → csound6, origin/csound6)
Author: Victor Lazzarini <victor.lazzarini@mu.ie>

fixed crash on channel setting with empty channel name

thanks Victor! Does one need to rebuild csound to pick this up or are releases online updated automatically?

thanks very much for jumping on it so fast.
iain

This fix will come out in the next release, unless you build your own Csound, in which case you might try it straight away.

ok thanks for the clarification. Will try building!
iain

It’s pretty straightforward, you only need libsndfile installed (which is easily built from sources).

Then it’s just cmake. I have also built my own flex and bison, but I think this may not be needed.

Prof. Victor Lazzarini
Maynooth University
Ireland