vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| On Mon, 16 May 2005, Han Boetes wrote: > Sven Dehmlow wrote: > > size_t is usually typedef'ed as something unsigned, but snprintf may > > return signed integer values. That's why it's not very clever to use size_t > > here. > > > > /usr/src/sys/arch/i386/include/ansi.h: > > #define _BSD_SIZE_T_ unsigned int > > > > /usr/src/include/stddef.h: > > typedef _BSD_SIZE_T_ size_t; > > > > printf(3): > > int (!) > > snprintf(char *str, size_t size, const char *format, ...); > > > > or in pseudo-C: > > unsigned int != int > > > > Hope this helps on the way to enlightment ... ;-) > > Yes I know. But sizeof() returns size_t. Suppose int has a range > from -128 to 127 and size_t from 0 to 255. > > What will you do if sizeof() returns, say, 130... If nothing helps compare it with a constant first, but never, never, never fill an unsigned type with a signed value. Sven |