Repository navigation
texttopdf: don't highlight a comment token's first char across a page wrap - #273
Open
ManasBagul23 wants to merge 1 commit into
Open
ManasBagul23 wants to merge 1 commit into
ManasBagul23 wants to merge 1 commit into
Conversation
… wrap
When C/C++ pretty-printing recognizes the start of a comment ('/*' or
'//'), the highlighter marks the opening character bold/italic by
writing doc.Page[line][column - 1].attr -- "column - 1" because by the
time this runs, the loop has already advanced past that character to
the current one (lastch == '/', ch == '*' or '/').
If the '/' happened to be the very last character that fit on the
current line/page, the automatic wrap earlier in the same iteration
resets "column" to 0 (and, on a page boundary, calls write_page(),
which allocates/clears a fresh doc.Page buffer) before this highlight
code runs. "column - 1" then becomes -1, writing two bytes immediately
before the new page's heap allocation (OpenPrinting#196).
Skip the highlight when column is 0 -- there is no previous cell on
the current line to mark in that case, since the '/' that started the
comment was wrapped onto a page/line that no longer exists at this
point.
Verified by tracing the ordering of the wrap block (which resets
column/line/page before this code runs) against this write, confirming
column == 0 here always means the only candidate previous cell was on
the page just flushed, not the current one. No C build toolchain
available locally to compile-check.
Fixes OpenPrinting#196
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When C/C++ pretty-printing recognizes the start of a comment (
/*or//), the highlighter marks the opening character bold/italic by writingdoc.Page[line][column - 1].attr—column - 1because by the time thisruns, the loop has already advanced past that character to the current one
(
lastch == '/',ch == '*'or'/').If the
/happened to be the very last character that fit on the currentline/page, the automatic wrap earlier in the same iteration resets
columnto 0 (and, on a page boundary, callswrite_page(), whichallocates/clears a fresh
doc.Pagebuffer) before this highlight coderuns.
column - 1then becomes -1, writing two bytes immediately beforethe new page's heap allocation.
Fixes #196
Fix
Skip the highlight when
columnis 0 — there is no previous cell on thecurrent line to mark in that case, since the
/that started the commentwas wrapped onto a page/line that no longer exists at this point.
Verified
No C build toolchain available locally to compile-check. Verified by
tracing the ordering of the wrap block (which resets
column/line/pagebefore this code runs) against this write, confirming
column == 0herealways means the only candidate previous cell was on the page just
flushed, not the current one.