07-21-2011 09:06 PM
Hello,
I just created this function, it will get a shared variable with CNVGetScalarDataValue (statDa, CNVString, &throughputStat); and strcat another string to it and then write it back.
But I am having this message : Missing terminating Null in string argument and it is pointing to throughputStat.
Any help here? Thank you.
void SendMessg(char *messg)
{
int strlenMessg;
int strlenThroughputStat;
strlenMessg = strlen (messg);
CNVCreateScalarDataValue (&statDa, CNVString,"");
CNVRead (tPutStat, CNVWaitForever, &statDa);
CNVGetScalarDataValue (statDa, CNVString, &throughputStat);
strlenThroughputStat = strlen (throughputStat);
throughputStat = malloc(strlenThroughputStat + strlenMessg +1);
strcat(throughputStat, messg);
CNVCreateScalarDataValue (&statData, CNVString,"");
CNVSetScalarDataValue (statData, CNVString,throughputStat);
CNVWrite (writer, statData, CNVWaitForever);
Sleep(100);
}
07-22-2011 12:15 AM
strlen expects a pointer to a NUL-terminated string - so you need to make sure that before calling strlen your string is NUL-terminated...
07-22-2011 12:18 AM
CNVGetScalarDataValue (statDa, CNVString, &throughputStat); strlenThroughputStat = strlen (throughputStat); throughputStat = malloc(strlenThroughputStat + strlenMessg +1); strcat(throughputStat, messg);
You are overwriting the memory allocation done by CNVGetScalarDataValue() with a new allocation by malloc().This allocation does not point to the same address.
I'am not sure if you can use realloc on memory allocated by CNVGetScalarDataValue(). So do something like
[...]
char * help;
[...]
CNVGetScalarDataValue (statDa, CNVString, &help);
strlenThroughputStat = strlen (help);
throughputStat = malloc(strlenThroughputStat + strlenMessg +1);
sprintf( throughputStat,"%s%s" ,help,messg);
CNVFreeMemory (help);
[...]
07-22-2011 08:49 AM
What I am trying to do here is that, a shared variable "throughputStat" is being created (a labview vi will use is as a message receive) . So time to time I have to get hat veriable back concatenate another string message to it (string " *messg") and write it again with CNV write...
so read throughputStat, concatenate *messg to it and write the message back... So the strcat part seems to give me trouble.
This is what I am trying to do.
Thanks for further help.
07-26-2011 12:07 AM
I think you need to create another shared variable for writing back the information. You can't use the same variable to write back, as long as you need a bigger size.
Just to make clear again: The malloc() overwrites the pointer that points to to the memory area containing the throughputStat string by another pointer pointing to uninitialized memory,which doesn't need to contain any ASCII 0 character as string terminator.
11-17-2018 07:36 PM - edited 11-17-2018 07:37 PM
Wrong thread...