10-18-2010 12:43 AM
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!
10-18-2010 01:04 AM
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.
10-18-2010 12:58 PM
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.
10-19-2010 08:41 AM
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!
10-19-2010 08:47 AM - edited 10-19-2010 08:53 AM
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.
10-19-2010 09:07 AM
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...