[Csnd-dev] csoundGetStringChannel last character missing

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[Csnd-dev] csoundGetStringChannel last character missing

Tarmo Johannes-3

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


Reply | Threaded
Open this post in threaded view
|

Re: [Csnd-dev] csoundGetStringChannel last character missing

rorywalsh
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 <[hidden email]> 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



Reply | Threaded
Open this post in threaded view
|

Re: [Csnd-dev] csoundGetStringChannel last character missing

jpff
In reply to this post by Tarmo Johannes-3
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
>
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd-dev] csoundGetStringChannel last character missing

Tarmo Johannes-3
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,
> >
> > tarmo