From MSDN
'strnlen is not a replacement for strlen; strnlen is intended to be used only to calculate the size of incoming untrusted data in a buffer of known size—for example, a network packet. strnlen calculates the length but doesn't walk past the end of the buffer if the string is unterminated.'
I came upon strnlen in some source, never seen it before, seems that it's used in Unix and MS have their own version though not standard C/C++.
So it checks a string against a buffer of known size and if > buffer returns string up to max buffer size.
So don't see how this is needed, terminated or not strlen is less work and does same thing?
as even if you used strnlen you would still have to at least sayCode:size_t buffer = 1000; if (strlen(str) > buffer){ return -1 }
Code:size_t buffer = 1000; unsigned int i_str = strnlen(str, buffer); if i_str == buffer{ return -1 }