On Monday 2009-07-13 22:19 +0000, Roy Marples output: :Module Name: src :Committed By: roy :Date: Mon Jul 13 22:19:25 UTC 2009 : :Modified Files: : src/distrib/sets/lists/comp: mi : src/include: stdio.h : src/lib/libc/stdio: Makefile.inc stdio.3 :Added Files: : src/lib/libc/stdio: getdelim.3 getdelim.c getline.c : :Log Message: :Add implementations for getdelim(3) and getline(3). [...] :cvs rdiff -u -r0 -r1.1 src/lib/libc/stdio/getdelim.3 \ : src/lib/libc/stdio/getdelim.c src/lib/libc/stdio/getline.c
arg #3 of memchr() is size_t. I don't know how "Ensure that the resultant buffer length fits in ssize_t" is supposed to work. You're promoting SSIZE_MAX from ssize_t to ssize_t, then comparing with an already possibly overflowed variable "newlen". Also I didn't really look through the code so I don't know why you added an extra one there in the comparison. Maybe you want something like the following. Regards, Geoff Index: lib/libc/stdio/getdelim.c =================================================================== RCS file: /cvsroot/src/lib/libc/stdio/getdelim.c,v retrieving revision 1.1 diff -u -r1.1 getdelim.c --- lib/libc/stdio/getdelim.c 13 Jul 2009 22:19:25 -0000 1.1 +++ lib/libc/stdio/getdelim.c 14 Jul 2009 01:13:02 -0000 @@ -79,18 +79,18 @@ } /* Scan through looking for the separator */ - p = memchr(fp->_p, sep, fp->_r); + p = memchr(fp->_p, sep, (size_t)fp->_r); if (p == NULL) len = fp->_r; else len = (p - fp->_p) + 1; - newlen = off + len + 1; /* Ensure that the resultant buffer length fits in ssize_t */ - if (newlen > (size_t)SSIZE_MAX + 1) { + if (off + len + 1 > (unsigned int)SSIZE_MAX) { errno = EOVERFLOW; goto error; } + newlen = off + len + 1; if (newlen > *buflen) { if (newlen < MINBUF) newlen = MINBUF;