Skip to content

Conversation

@giusguerrini
Copy link

@giusguerrini giusguerrini commented Jan 23, 2026

In case of line like

#else (...many spaces...) ...garbage...

i.e., there is garbage after a valid directive, and there are many spaces in between, the program termintated wih an exception. The program crashed because of an index overflow in a string. The offending code is in the construction of the error message. To fix it, I simplified the error message by showing the whole line instead of the parts. It is not perfect, because the message is slightly less precise, but in my opinion it's explanatory enough.

@dbremner dbremner self-assigned this Jan 25, 2026
@dbremner
Copy link
Owner

Thanks for the PR. I can see how this avoids the crash, but I'd like to understand the root cause before merging.
I've looked at the code and I think the issue is that pretty() returns a transformed version of the line (possibly with whitespace normalized) while the chewer position is based on the original buffer. If you could share a minimal test file that triggers the crash, I can verify that theory and fix it properly, probably by reporting the column position instead of trying to split the line.

@giusguerrini
Copy link
Author

giusguerrini commented Jan 26, 2026

Hi dbremmer, here's a minimal example of C source that generates the exception:

#ifdef XXX
int x[XXX];
#else                                                                "
int x[10];
#endif

As you correctly supposed, the exception is due to the fact that the string containing the original line is compressed to remove additional spaces, but the index of the offending character (a double quote in this case) is not decreased accordingly.

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