Optimization I'd like to see compilers be able to make: if (strlen(s)>100) -> if (strnlen(s,101)>100)
-
Show this thread
-
Replying to @RichFelker
If "s" is between 1 and 100 bytes longer than the range of size_t, is this defined as true, or is strlen() itself undefined for this case? (I don't see this case explicitly covered in C99 std, but strlen returns size_t, not ssize_t, so I would assume overflow is well defined?)
1 reply 0 retweets 0 likes -
Replying to @oe1cxw @RichFelker
there's no way to create an object larger than the range of size_t in C, and how would you access all of it if there were? And some implementations (musl) only allow allocations in the range of ssize_t.
1 reply 0 retweets 1 like -
Replying to @koorogi @RichFelker
I don't think size_t is required to be the same size as a pointer. You might not be able to create such a large string yourself on the heap, but that doesn't mean it can't already exist...
3 replies 0 retweets 0 likes
size_t is an unsigned integer type for representing the size of an object. The standard is poorly vague about what requirements that imposes, but any interpretation allowing objects whose size it can't represent is a critically broken one.
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.