Skip to content

fix(zero): terminate each entry with a NUL separator - #364

Open
MsfPablo wants to merge 1 commit into
equationzhao:masterfrom
MsfPablo:fix/zero-nul-separator
Open

MsfPablo wants to merge 1 commit into
equationzhao:masterfrom
MsfPablo:fix/zero-nul-separator

Conversation

@MsfPablo

@MsfPablo MsfPablo commented Sep 1, 2026

Copy link
Copy Markdown

What

--zero is meant to end each output entry with a NUL byte, but the Zero printer wrote each entry's content and never wrote \x00, so entries concatenated with no delimiter and the stream couldn't be split safely.

Fixes #333.

Repro

Two files a, b in a dir:

g --no-config --disable-index --classic -A --zero "$tmp" | od -An -tx1c

Before:

   61   62
   a    b

After:

   61  00  62  00
   a \0   b \0

Change

internal/display/printer.go — write one NUL byte after every entry in Zero.Print. A single entry is still terminated, so a reader doesn't block waiting for a delimiter that never comes.

Tests

internal/display/zero_test.goTestZeroPrinterTerminatesEachEntryWithNUL asserts the exact stream a\x00b\x00c\x00, and TestZeroPrinterSingleEntryStillTerminated covers the single-entry case. Both fail on the pre-fix code (only vs only\x00).

go test ./internal/display/... passes; gofumpt --extra -w -l . clean.

--zero is documented to end each output entry with a NUL byte, but the
Zero printer wrote each entry's content and never wrote \x00, so
consecutive entries concatenated with no delimiter and consumers could
not safely split the stream.

Write one NUL byte after every entry. A single entry is still
terminated, so a reader does not block waiting for a delimiter that
never arrives.

Fixes equationzhao#333
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] --zero concatenates entries instead of writing NUL separators

1 participant