Menu

The 'or' that read too far
📰

The 'or' that read too far

DEV Community: rust·arcker·about 21 hours ago
#OpAvOTtx
#devtorust#devto#dev#true#left
Reading 0:00
15s threshold

Verbose is a small language I build that compiles to native x86-64, to WebAssembly, and also runs in an interpreter. This post walks through one bug that showed up differently in each of those, with real binaries. It stands on its own; no Verbose knowledge needed.

Before reading the first line of a notebook, you check there is something in it. Nobody does it the other way round. Nobody opens an empty notebook, tries to read line one, and then thinks "ah, it was empty, never mind".

In Verbose, that precaution is written like this:

length(i.s) == 0 or byte_at(i.s, 0) > 0

Enter fullscreen mode

Exit fullscreen mode

"The text is empty, or its first byte is nonzero." If the text is empty, the question is settled by the first half, and the second half, which reads byte number zero, has no reason to be asked. It cannot be, in fact: an empty text has no byte number zero.

On October 8th this line protected the program perfectly when Verbose compiled it to a native binary.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.