Skip to content

Fix EOF handling in calculator.dana main loop#81

Merged
kostis merged 1 commit intokostis:masterfrom
JohnnyPol:fix/calculator
Aug 11, 2025
Merged

Fix EOF handling in calculator.dana main loop#81
kostis merged 1 commit intokostis:masterfrom
JohnnyPol:fix/calculator

Conversation

@JohnnyPol
Copy link
Contributor

This change adds a single line at the start of the lines loop in calculator.dana:

buf[0] := '\0'

This ensures the buffer is always null-terminated before reading new input.
When readString reaches EOF without writing anything, strlen(buf) now returns 0 instead of reading stale data from previous iterations.

Why it was necessary:

Without clearing the buffer, when having an input file for ./a.out < calculator.input the loop would be infinite. This fix guarantees that the loop terminates cleanly at EOF.

@kostis kostis merged commit 9373d0a into kostis:master Aug 11, 2025
2 checks passed
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