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 -
Replying to @oe1cxw @RichFelker
they aren't. I think on DOS, a far pointer is 32 bits while size_t is 16. Sure, you can wrangle more than 64KB of consecutive memory together. But C still doesn't have a concept of such a large object, so I think calling the standard library functions on it are going to cause UB.
1 reply 0 retweets 1 like
In the large or huge model size_t should be 32-bit.
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.