BUG - string.h library

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

BUG - string.h library

453 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by brownm on Fri Apr 01 21:13:55 MST 2016
Hi there

I'm trying to use the string.h library function - strncasecmp I think that there is a bug in it.


static const char *mon[12] = {
"January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December"
};


void mkb_test(void){
size_t len;
len = strlen(mon[5]);
if (strncasecmp(mon[5], "dec 2011", len) == 0){
printf ("how does that match");

}

}



Any thoughts are appreciated.

Regards
Marshall
0 Kudos
4 Replies

368 Views
lpcware
NXP Employee
NXP Employee
bump
0 Kudos

368 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by BoonBestekla on Thu Apr 07 05:31:36 MST 2016
I work at the same company as Robert who posted in this thread before. We looked into the disassembly and think the instruction at 0x4e5a5 should be "beq.n  0x4e5ac" instead of "bcs.n 0x4e5ac".

0004e584:   push {r3, r4, r5, r6, r7, lr}
0004e586:   mov r5, r0
0004e588:   mov r6, r1
0004e58a:   adds r7, r0, r2
0004e58c:   cmp r5, r7
0004e58e:   beq.n 0x4e5b0 <strncasecmp+44>
0004e590:   ldrb.w r0, [r5], #1
0004e594:   bl 0x4c840 <tolower>
0004e598:   uxtb r4, r0
0004e59a:   ldrb.w r0, [r6], #1
0004e59e:   bl 0x4c840 <tolower>
0004e5a2:   uxtb r0, r0
0004e5a4:   cmp r4, r0
0004e5a6:   bcs.n 0x4e5ac <strncasecmp+40>
0004e5a8:   subs r0, r4, r0
0004e5aa:   pop {r3, r4, r5, r6, r7, pc}
0004e5ac:   cmp r4, #0
0004e5ae:   bne.n 0x4e58c <strncasecmp+8>
0004e5b0:   movs r0, #0
0004e5b2:   pop {r3, r4, r5, r6, r7, pc}
0 Kudos

368 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Wed Apr 06 10:18:46 MST 2016
You appear to be correct - strncasecmp() will in some circumstances incorrectly report a match. We'll investigate further for fixing in a future release.

Regards,
LPCXpresso Support
0 Kudos

368 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by robert hulsebos on Wed Apr 06 06:31:16 MST 2016
We encountered the same problem last week (LPCXpresso v7.9.2). According to release notes these string functions were first introduced with v7.5.0. Nobody noticed this bug before?
What version of LPCXpresso are you using?
0 Kudos