STD_CompareLString

Syntax

#include <nitro/std.h>

int STD_CompareLString( const char* str1, const char* str2, int len );
int STD_StrLCmp( const char* str1, const char* str2, int len );

Arguments

str1 Pointer to the compared string.
str2 Pointer to the compared string.
len Length of the string to compare.

Return Values

Returns 0 if the compared strings are the same.

Description

Compares only len characters between the two strings str1 and str2. This has the same behavior as the strlcmp function.

The difference when compared to the STD_CompareNString function lies in the fact that the two strings are not considered a match even if the length of len is compared and found to match, but the next character in str1 is not NULL.

When detecting the difference between buffers as a means to prevent buffer overflow, it is possible to prevent the comparison of addresses that come after the buffer length, by replacing a comparison function without a length restriction check with a function that includes a length restriction check.

Although replacing the strcmp function with the strncmp function serves as an actual example, if you simply specify the buffer size in the len parameter used to specify length when using the strncmp function, if the result of comparison is a match, the result "match" is returned even if the buffer overflows. Buffer overflow can therefore also be detected based on the fact that the result "match" is not returned if the NULL character is not found within (len+1) characters when using the strlcmp function.

It is therefore best to use the STD_CompareLString function when using string comparison for the purpose of checking buffers.

STD_StrLCmp is defined as another name for STD_StrCompareLString.

See Also

STD_CompareString
STD_CompareNString

Revision History

2008/10/06 Added a description of the difference with the STD_CompareNString function.
2008/09/26 Revised definitions.
2005/10/05 Initial version.


CONFIDENTIAL