Csound Csound-dev Csound-tekno Search About

[Csnd-dev] csoundGetStringChannel last character missing

Date2018-04-30 08:06
FromTarmo Johannes
Subject[Csnd-dev] csoundGetStringChannel last character missing

Hi,

Users of CsoundQt reported that string channels are not working properly any more -  last 

character is omitted.  Seehttps://github.com/CsoundQt/CsoundQt/issues/263


With  Csound 6.10 it works fine.

The code in CsoundQt that is getting the value is:

char chanString[2048]; 

csoundGetStringChannel(ud->csound, ud-

>outputStringChannelNames[i].toLocal8Bit().constData(),

                                   chanString);

Here the string is returned too short, "Hell", instead of "Hello".

Tested on Linux, Csound from git develop 29.04.

Can it be that it is caused by commit in Csound by John:

a7394d5d831c8679fc0c934db6c5cc29c475bf1d

Top/threadsafe.c

@@ -624,8 +624,8 @@ void csoundGetStringChannel(CSOUND *csound, const char *name, 

char *string)

       csoundSpinLock(lock);

     if (string != NULL && chstring != NULL) {

       n2 = strlen(chstring);

-      strncpy(string,chstring, n2);

-      string[n2] = 0;

+      strNcpy(string,chstring, n2);

+      //string[n2] = 0;

     }

Also please note that if you set empty string to channel with chnset "", "channel"

csoundGetStringChannel may return garbage, so 

string[n2] = 0;

might be still necessary.

greetings,

tarmo



Date2018-04-30 12:43
FromRory Walsh
SubjectRe: [Csnd-dev] csoundGetStringChannel last character missing
That's odd Tarmo, I'm not noticing the issue on Cabbage? I'm using Csound::GetStringChannel() but that just interfaces the C function. I'm using 6.11, built from source last Friday. Let me know if you wish me to dig a little further..

On 30 April 2018 at 08:06, Tarmo Johannes <trmjhnns@gmail.com> wrote:

Hi,

Users of CsoundQt reported that string channels are not working properly any more -  last 

character is omitted.  Seehttps://github.com/CsoundQt/CsoundQt/issues/263


With  Csound 6.10 it works fine.

The code in CsoundQt that is getting the value is:

char chanString[2048]; 

csoundGetStringChannel(ud->csound, ud-

>outputStringChannelNames[i].toLocal8Bit().constData(),

                                   chanString);

Here the string is returned too short, "Hell", instead of "Hello".

Tested on Linux, Csound from git develop 29.04.

Can it be that it is caused by commit in Csound by John:

a7394d5d831c8679fc0c934db6c5cc29c475bf1d

Top/threadsafe.c

@@ -624,8 +624,8 @@ void csoundGetStringChannel(CSOUND *csound, const char *name, 

char *string)

       csoundSpinLock(lock);

     if (string != NULL && chstring != NULL) {

       n2 = strlen(chstring);

-      strncpy(string,chstring, n2);

-      string[n2] = 0;

+      strNcpy(string,chstring, n2);

+      //string[n2] = 0;

     }

Also please note that if you set empty string to channel with chnset "", "channel"

csoundGetStringChannel may return garbage, so 

string[n2] = 0;

might be still necessary.

greetings,

tarmo




Date2018-04-30 16:16
Fromjpff
SubjectRe: [Csnd-dev] csoundGetStringChannel last character missing
Probably my fault -- I changed it on 23 Jan this year.  Will partially 
revert.

On Mon, 30 Apr 2018, Tarmo Johannes wrote:

> 
> Hi,
> 
> Users of CsoundQt reported that string channels are not working properly any
> more -  last 
> 
> character is omitted.  Seehttps://github.com/CsoundQt/CsoundQt/issues/263
> 
> 
> With  Csound 6.10 it works fine.
> 
> The code in CsoundQt that is getting the value is:
> 
> char chanString[2048]; 
> 
> csoundGetStringChannel(ud->csound, ud-
> 
> >outputStringChannelNames[i].toLocal8Bit().constData(),
> 
>                                    chanString);
> 
> Here the string is returned too short, "Hell", instead of "Hello".
> 
> Tested on Linux, Csound from git develop 29.04.
> 
> Can it be that it is caused by commit in Csound by John:
> 
> a7394d5d831c8679fc0c934db6c5cc29c475bf1d
> 
> Top/threadsafe.c
> 
> @@ -624,8 +624,8 @@ void csoundGetStringChannel(CSOUND *csound, const char
> *name, 
> 
> char *string)
> 
>        csoundSpinLock(lock);
> 
>      if (string != NULL && chstring != NULL) {
> 
>        n2 = strlen(chstring);
> 
> -      strncpy(string,chstring, n2);
> 
> -      string[n2] = 0;
> 
> +      strNcpy(string,chstring, n2);
> 
> +      //string[n2] = 0;
> 
>      }
> 
> Also please note that if you set empty string to channel with chnset "",
> "channel"
> 
> csoundGetStringChannel may return garbage, so 
> 
> string[n2] = 0;
> 
> might be still necessary.
> 
> greetings,
> 
> tarmo
> 
> 
> 
>

Date2018-04-30 20:37
FromTarmo Johannes
SubjectRe: [Csnd-dev] csoundGetStringChannel last character missing
Thanks a lot,  John!

Works now as expected.

greetings,
tarmo

On esmaspäev, 30. aprill 2018 18:16.50 EEST jpff wrote:
> Probably my fault -- I changed it on 23 Jan this year.  Will partially
> revert.
> 
> On Mon, 30 Apr 2018, Tarmo Johannes wrote:
> > Hi,
> > 
> > Users of CsoundQt reported that string channels are not working properly
> > any more -  last
> > 
> > character is omitted.  Seehttps://github.com/CsoundQt/CsoundQt/issues/263
> > 
> > 
> > With  Csound 6.10 it works fine.
> > 
> > The code in CsoundQt that is getting the value is:
> > 
> > char chanString[2048]; 
> > 
> > csoundGetStringChannel(ud->csound, ud-
> > ooo
> > >outputStringChannelNames[i].toLocal8Bit().constData(),
> > 
> >                                    chanString);
> > 
> > Here the string is returned too short, "Hell", instead of "Hello".
> > 
> > Tested on Linux, Csound from git develop 29.04.
> > 
> > Can it be that it is caused by commit in Csound by John:
> > 
> > a7394d5d831c8679fc0c934db6c5cc29c475bf1d
> > 
> > Top/threadsafe.c
> > 
> > @@ -624,8 +624,8 @@ void csoundGetStringChannel(CSOUND *csound, const char
> > *name, 
> > 
> > char *string)
> > 
> >        csoundSpinLock(lock);
> > 
> >      if (string != NULL && chstring != NULL) {
> > 
> >        n2 = strlen(chstring);
> > 
> > -      strncpy(string,chstring, n2);
> > 
> > -      string[n2] = 0;
> > 
> > +      strNcpy(string,chstring, n2);
> > 
> > +      //string[n2] = 0;
> > 
> >      }
> > 
> > Also please note that if you set empty string to channel with chnset "",
> > "channel"
> > 
> > csoundGetStringChannel moooay return garbage, so 
> > 
> > string[n2] = 0;
> > 
> > might be still necessary.
> > 
> > greetings,
> >