StdLib: Fix pointer arithmetic issues in the strncasecmp function.

The original Linux code tried to be too fancy so the internal pointers got out of sync.
Rewrote the function to at least be more clear.
Regardless, it now works properly.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Daryl McDaniel <daryl.mcdaniel@intel.com>
Reviewed by: matthew.stanbro@intel.com
Reviewed by: erik.c.bjorge@intel.com


git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14664 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Daryl McDaniel 2013-09-13 00:46:19 +00:00 committed by darylm503
parent ac7f472be7
commit 3a2f8f4216
1 changed files with 22 additions and 19 deletions

View File

@ -60,19 +60,22 @@ __weak_alias(strncasecmp,_strncasecmp)
int
strncasecmp(const char *s1, const char *s2, size_t n)
{
int CompareVal;
_DIAGASSERT(s1 != NULL);
_DIAGASSERT(s2 != NULL);
if (n != 0) {
const unsigned char *us1 = (const unsigned char *)s1,
*us2 = (const unsigned char *)s2;
do {
if (tolower(*us1) != tolower(*us2++))
return (tolower(*us1) - tolower(*--us2));
if (*us1++ == '\0')
CompareVal = tolower(*s1) - tolower(*s2);
if (CompareVal != 0) {
return (CompareVal);
}
++s1;
++s2;
if (*s1 == '\0') {
break;
}
} while (--n != 0);
}
return (0);