You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@msmeissn Thanks so much.
I think +2, rather than +3, is good enough. Suppose line="abc\n" 4 bytes. realloc(...,strlen(line),2) will allocate 6 bytes which is capable of making sprintf() to add line=3 bytes ,'\' and 'n' 2 bytes pluses extra '\0' byte totally 6 bytes.
ps: line is already removed its '\n' ahead of sprintf() by line[strlen(line) - 1] = 0;
Activity
msmeissn commentedon Apr 9, 2025
also a bit below there is:
weird, line might have a \n already, and is double backslash \n here correct? if this is double backslash n , it needs to be
+3 above
dennis-tseng99 commentedon Apr 13, 2025
@msmeissn Thanks so much.
I think +2, rather than +3, is good enough. Suppose line="abc\n" 4 bytes. realloc(...,strlen(line),2) will allocate 6 bytes which is capable of making sprintf() to add line=3 bytes ,'\' and 'n' 2 bytes pluses extra '\0' byte totally 6 bytes.
ps: line is already removed its '\n' ahead of sprintf() by line[strlen(line) - 1] = 0;