LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Missing terminating Null

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);
 
 
}

0 Kudos
Message 1 of 6
(4,918 Views)

strlen expects a pointer to a NUL-terminated string - so you need to make sure that before calling strlen your string is NUL-terminated...

0 Kudos
Message 2 of 6
(4,909 Views)
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);

[...]

      

 

 

 

0 Kudos
Message 3 of 6
(4,908 Views)

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.

0 Kudos
Message 4 of 6
(4,899 Views)

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.

0 Kudos
Message 5 of 6
(4,876 Views)

Wrong thread...

Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 6 of 6
(3,528 Views)