Skip to content
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

optimize_clear_loop bail early if instructions struct too small #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

optimize_clear_loop bail early if instructions struct too small #8

wants to merge 1 commit into from

Conversation

rwhitworth
Copy link
Contributor

Helps avoid #7

@rwhitworth rwhitworth mentioned this pull request Jul 8, 2017
@julianneswinoga
Copy link
Owner

In what situation does the original code cause an error?

@rwhitworth
Copy link
Contributor Author

Example input: input.gz

It fixes this error as reported by valgrind:

==943710== Invalid read of size 1
==943710==    at 0x405722: optimize_clear_loop (optimize.c:77)
==943710==    by 0x401AA1: main (yabfc.c:136)
==943710==  Address 0x56df9b8 is 0 bytes after a block of size 8 alloc'd
==943710==    at 0x4C2DDCF: realloc (vg_replace_malloc.c:785)
==943710==    by 0x4018E1: main (yabfc.c:118)

@@ -70,7 +70,9 @@ bool optimize_compress_PTR(INSTRUCTIONS *instructions, int *position, CODE *code
bool optimize_clear_loop(INSTRUCTIONS *instructions, int *position, CODE *code) {
if (globalOptions.optimize < 2) // Only do on optimization level 2 and higher
return false;

if (instructions->size - (*position) < 3)
Copy link
Owner

Choose a reason for hiding this comment

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

Can you change the 3 to be based on the number of characters being checked? I.e. sizeof(clearLoop) - 1?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants