Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion qtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,18 @@ bool do_remove_head(int argc, char *argv[])
if (removes[0] == '\0') {
report(1, "ERROR: Failed to store removed value");
ok = false;
} else if (removes[string_length + 1] != 'X') {
}

bool check_overflow = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder the necessity of variable check_overflow. Can you eliminate it by replacing for with while?

int i = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the scope of int i into for-loop. So, it would look like the following:

for (int i = string_length + 1; i < string_length + STRINGPAD; i++) {
    ...

for (i = string_length + 1; i < string_length + STRINGPAD; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the algorithm descriptions about checking and validating memory here.

if (removes[i] != 'X') {
check_overflow = false;
break;
}
}

if (!check_overflow) {
report(1,
"ERROR: copying of string in remove_head overflowed "
"destination buffer.");
Expand Down