This is a discussion on Re: more improvements for mg within the mailing.openbsd.tech forums, part of the OpenBSD category; --> Sven Dehmlow wrote: > size_t is usually typedef'ed as something unsigned, but snprintf may > return signed integer values. ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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... You have to take that into account as well. # Han |