LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

missing terminating null in string argument

When the statement is executed "if ((strstr (refData, "end section") != test) || (strstr (refData, "end file") != test))", it displayed "Missing terminating null in string argument".The error is about refData,refData is a variable.

I don't know why this problem turned up,because it did not always appear except serval parameters.

Please tell you how to resolve this problem.

Thank you!

0 Kudos
Message 1 of 6
(9,688 Views)

C assumes that a string is a character array with a terminating null character. This null character has ASCII value 0 and can be represented as just 0 or '\0'. This value is used to mark the end of meaningful data in the string. If this value is missing, many C string functions will keep processing data past the end of the meaningful data and often past the end of the character array itself until it happens to find a zero byte in memory, see here

 

So in order to resolve the problem make sure that your string ends with a null character.

0 Kudos
Message 2 of 6
(9,685 Views)

In addition to WolfGang's comments, I would look into the function CopyString which will automatically append an ascii null.  

 

...Or right clicking the background of the function panel of strncpy will explain a solution as well.  

 

Either way, you will need to know either the length of meaningful data in the array, or at least the length of the array to add an ascii null byte at the end.

 

0 Kudos
Message 3 of 6
(9,661 Views)

Thank you for your answer first,but I still  have some doubts about this problem.

The refData variable obtains the value from a extension .txt,this situation happened when it get a value.For example,refData received "inter_handover_allowed",all values before "inter_handover_allowed" are ok.the program is running normally.But there is a error when the value is "inter_handover_allowed".The error message is "missing terminating null in string argument".

If I delete some values before "inter_handover_allowed",the program can run successfully.I have no idea why this situation happens.

Please give me a help if you can,Thank you very much!

0 Kudos
Message 4 of 6
(9,627 Views)

Have you tried at least passing refData to the CopyString variable to get a null terminated string?  This would help in at least confirming this is where the issue is.  Or at least set some byte of the array to zero to see if it goes away.

 

It seems the issue may be occurring previously in your code that you have not displayed, and this function just happens to catch it.

 

Edit: What is your test variable?  usually I use the strstr and use != NULL or something similar.  This also may help us answer your issue.

0 Kudos
Message 5 of 6
(9,625 Views)

Is your character string refdata long enough to include both "inter_handover_allowed" and the teminating null character? If it happens that you define it as refdata [22] there is no space left for the termination character... 

0 Kudos
Message 6 of 6
(9,621 Views)