-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Check entire buffer in check overflow #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check entire buffer in check overflow #7
Conversation
do_remove_head() checked removes[string_length + 1] only, so q_remove_head() would pass the test when it try to write data to other place in the buffer, such as index string_length + 2. Check entire buffer to fix it.
qtest.c
Outdated
| } | ||
|
|
||
| bool check_overflow = true; | ||
| int i = 0; |
There was a problem hiding this comment.
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++) {
...
qtest.c
Outdated
|
|
||
| bool check_overflow = true; | ||
| int i = 0; | ||
| for (i = string_length + 1; i < string_length + STRINGPAD; i++) { |
There was a problem hiding this comment.
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.
| } else if (removes[string_length + 1] != 'X') { | ||
| } | ||
|
|
||
| /* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tweak the indention for comments.
Something like:
/*
How large is a queue before it's considered big.
This affects how it gets printed
and whether cautious mode is used when freeing the list
*/
qtest.c
Outdated
| Validate memory by checking removes's padding positions are still | ||
| initial value 'X'. | ||
| */ | ||
| bool check_overflow = true; |
There was a problem hiding this comment.
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?
Variable check_overflow isn't necessary.
qtest.c
Outdated
| break; | ||
| } | ||
| int i = string_length + 1; | ||
| while (i < string_length + STRINGPAD && removes[i] == 'X') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add parentheses. So, it becomes while ((i < string_length + STRINGPAD) && removes[i] == 'X') {
qtest.c
Outdated
| } | ||
|
|
||
| /* | ||
| Validate memory by checking removes's padding positions are still |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check for grammar within the comment.
do_remove_head() checked removes[string_length + 1] only, so q_remove_head() would unexpectedly pass the test when it attempts to write data to other place in the buffer, such as index string_length + 2. Check entire buffer to fix it.
- Test sysprog21#7 still failed, leave it for investigate - Match swp file in .gitignore
do_remove_head() checked removes[string_length + 1] only, so
q_remove_head() would pass the test when it try to write data to other
place in the buffer, such as index string_length + 2. Check entire
buffer to fix it.