The example proper usage of snprintf(3) (under Caveats) evokes a warning
when compiled with -Wextra. I presume casting ret to unsigned int would
be safe, but I'll defer to those who know the nuances.


#include<stdio.h>

int
foo(char* string) {
        char buffer[128];
        int ret = snprintf(buffer, sizeof(buffer), "%s", string);
        if (ret == -1 || ret >= sizeof(buffer))
                return 1;
        return 0;
}

% cc -c -Wextra foo.c 
foo.c: In function 'foo':
foo.c:7: warning: comparison between signed and unsigned

Reply via email to