I have been troubled by a problem of strlen
for a long time, here is the code:
char stack_protect[1000] = {0};
char temp[100] = { 0 };
memset(&temp, 1, 110);
int len = strlen(temp);
printf("test strlen of temp %d \n", len);
if (len > 100)
{
xxxx;
}
else
{
xxxx;
}
char stack_protect2[1000] = {0};
you can see, I passed a param temp
to strlen
, and the return value len
is surely 110
.
but the next statements if (len > 100)
evaluates to false!
system: linux
CPU architecture: 32 Bit ARM
SOC: nt98566
please help me! thank you
something I have test:
- if you assign
len
value to anotherint
variable, things will ok. like below
example:
char temp[100] = { 0 };
memset(&temp, 1, 110);
int len = strlen(temp);
int len1 = len;
if (len1 > 100) ? TRUE!
- the every byte of len:
0x6e, 0x00, 0x00, 0x00
- in another soc hisiv300 len:110 if len > 100? TRUE