top | item 33843745

(no title)

mh7 | 3 years ago

strlen() returns a size_t so you're already constrained to a maximum length of SIZE_MAX.

discuss

order

jstimpfle|3 years ago

This is hilarious. SIZE_MAX is at least as large as the largest string that you can put in your address space / memory anyway. Which is what the strlen() API already assumes.

That, plus you'd be a fool to store a huge string in this way anywhere (in or out of memory) in any case.

Someone|3 years ago

> SIZE_MAX is at least as large as the largest string that you can put in your address space / memory anyway.

Not necessarily. A 64-bit system could give processes an address space that’s significantly larger than half the full 64-bit address space and have an allocator that allows you to allocate a block of more than SIZE_MAX bytes (malloc takes a size_t, but you can use calloc)

pjmlp|3 years ago

Indeed, you just need to forget to put a terminator to get a nice memory dump.

jcelerier|3 years ago

If you use a different data structure you would maybe use a different API for accessing it too