- Posts: 849
- Thank you received: 170
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
If the name is restricted to 19, shouldn't MAX_NAME_LENGTH renamed somethings like NAME_BUFSIZE?
That way we know 20 is 19 chars +including \0 ?
Or, is there any reason the particuliar buffer that crash. Couldn't be a pointer?
and, instead of using strcpy, use strdup?
Please Log in or Create an account to join the conversation.
Salty wrote:
If the name is restricted to 19, shouldn't MAX_NAME_LENGTH renamed somethings like NAME_BUFSIZE?
That way we know 20 is 19 chars +including \0 ?
<snipped>
<snipped>
Probably just better to use strnlen() with n=MAX_NAME_LENGTH instead of strlen()? This way we are guaranteed to get our null byte.
The strnlen() function computes the length of the string s, up to maxlen
characters. The strnlen() function will never attempt to address more
than maxlen characters, making it suitable for use with character arrays
that are not guaranteed to be NUL-terminated.
Please Log in or Create an account to join the conversation.
Agreed.I guess it comes down to whether null is added or not. If the buffer holding the string is too full to take a terminating NUL then that can cause instability later on when that string needs to be parsed, is that right? While I'm personally leaning towards strnlen(), I think using strlen() and >= or MAX_NAME_LENGTH + 1 should functionally do the same as strlen() counts up to the terminating NUL.
I just wanted to explain why i choosed +1 instead of >=.I think the +1 fix is a hack. It would have to be done everywhere we allocate a buffer for a name.
Instead, we must limit to 19 chars, using <= instead of <. That is consistent with the buffer size.
Please Log in or Create an account to join the conversation.
This is true, and is to be expected! It's no less weird to implementI think the +1 fix is a hack. It would have to be done everywhere we allocate a buffer for a name.
Instead, we must limit to 19 chars, using <= instead of <. That is consistent with the buffer size.
Please Log in or Create an account to join the conversation.
tbaMUD © 2024