vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| In message <20050516151748.GA1337@moule.localdomain> so spake Alexandre Ratchov (alex-contact): > int ret; > char foo[100]; > > ... > ret = snprintf(foo, sizeof(foo), "%s", input); > if (ret < 0 || (size_t)ret >= sizeof(foo)) > > > -1 means that snprintf failed and negative number of chars is meaningless. > This works if sizeof(foo) > INT_MAX because res is converted to size_t. > Have i missed something? While this does look OK I really don't see the need for the cast to size_t. In practice sizeof(foo) will not be > INT_MAX unless you are creating 2GB data structures on the stack and the stack is not big enough to hold such a data structure anyway. - todd |