You’ve added that the string is in shared memory. That’s guaranteed readable, and of fixed size. You can therefore use size_t MaxPossibleSize = startOfSharedMemory + sizeOfSharedMemory - input; strnlen(input, MaxPossibleSize)
(mind the extra n
in strnlen
).
This will return MaxPossibleSize
if there’s no \0
in the shared memory following input
, or the string length if there is. (The maximal possible string length is of course MaxPossibleSize-1
, in case the last byte of shared memory is the first \0
)