看板 DFBSD_submit 關於我們 聯絡資訊
On Mon, 3 Jan 2005 11:40:00 -0800 Chris Pressey <cpressey@catseye.mine.nu> wrote: > Or to take another example, this one from SUSv3: > > "SYNOPSIS > > #include <stdio.h> > ... > int snprintf(char *restrict s, size_t n, > const char *restrict format, ...); > ... > > RETURN VALUE > > ... > Upon successful completion, the snprintf() function shall return > the number of bytes that would be written to s had n been > sufficiently large excluding the terminating null byte." My mistake: snprintf can return -1, according to POSIX, but our manual page is sufficiently confusing about it that I read it as meaning that it cannot. I'll try to fix our manual page. > In other words, snprintf can never return a negative number. Yet its > return value is signed. This means that the fairly common idiom > > if (snprintf(buf, sizeof(f), f, ...) > sizeof(f)) { err(); } This also means this idiom is an incomplete check, and I'll fix them as I come to them. -Chris