Skip to content

Fix subtle bug for SIMD finding new line in chapter 10-4#96

Open
YukunJ wants to merge 1 commit intodendibakh:mainfrom
YukunJ:patch
Open

Fix subtle bug for SIMD finding new line in chapter 10-4#96
YukunJ wants to merge 1 commit intodendibakh:mainfrom
YukunJ:patch

Conversation

@YukunJ
Copy link
Copy Markdown

@YukunJ YukunJ commented Nov 9, 2025

Brief:

  • the code might be incorrect when there are more than 1 newliner \n in 8-byte chunks. Since we are shifting mask after we find a newliner, eolPos is a relative position (relative to mask) in this chunk. But uint32_t curLen = (pos - lineBeginPos) + eolPos; is an absolute position.

  • understood this is just demo purpose. But shift 8 bytes is UB.

I had a test version on this working here (dendibakh/perf-ninja@cf70700)

@dendibakh
Copy link
Copy Markdown
Owner

Yes, I decided to keep the code as simple as possible.
Changing the listing also requires also changing surrounding text as there are references to the line numbers.
Instead of fixing the code, I would rather add a footnote or a sentence in the text that there is an UB.

@YukunJ YukunJ force-pushed the patch branch 3 times, most recently from 5b69e52 to ff2cb64 Compare November 17, 2025 00:27
@YukunJ
Copy link
Copy Markdown
Author

YukunJ commented Nov 17, 2025

Sure that makes sense. I will add a comment for that.

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