strncmp("aa", "ab", -1)

Tobias Poschwatta tp at fonz.de
Wed Sep 24 08:09:03 UTC 2008


Hi,

while investigating wrong results from busybox's uniq applet, I found
that strncmp returns unexpected results for n == -1.

Here's the test program:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char **argv)
{
        printf("%d\n", strncmp("aa", "ab", -1));
        exit(0);
}


On glibc/i386, it prints -1.
On uclibc/arm/oabi/no-thumb, I get 0.

My uclibc config is attached. I think it's using the assember version
in libc/string/arm/strncmp.S. Unfortunately, I don't know enough ARM
assembler to check that the function is handling n correctly as
unsigned long (which is what size_t is supposed to be, right?).

Thanks.

Tobias




More information about the uClibc mailing list