Skip to content

Commit 1fbf053

Browse files
authored
Fix readlines.c
At the test-part of the if-statement, please recall that we're checking for the *total* number of characters used in storage out of 10,000; we're not checking for the string-length of stored_lines added with the current line length being more than 10,000. Especially when neither is stored_lines itself being changed in the program nor is the length of the current line allowed to be more than 1,000 to begin with.
1 parent 7f3097e commit 1fbf053

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

chapter_5/exercise_5_07/readlines.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ int readlines(char *line_ptr[], int max_nr_of_lines, char *stored_lines)
4848
{
4949
// Checking if the current # of lines exceeds the max # of lines that can be stored
5050
// Also checking if the max # of chars from the stored_lines buffer is not exceeded
51-
if (nr_of_lines >= max_nr_of_lines || (strlen(stored_lines) + len) > MAXSTORE)
51+
if (nr_of_lines >= max_nr_of_lines || stored_lines + MAXSTORE - p < len)
5252
{
5353
return -1;
5454
}

0 commit comments

Comments
 (0)