asoffer / Icarus

An experimental general-purpose programming language
Apache License 2.0
9 stars 2 forks source link

file.Lines returns slices of length 0xAAAAAAAAAAAAAAAA #110

Closed perimosocordiae closed 2 years ago

perimosocordiae commented 2 years ago

Looks like the length field of the slice is left uninitialized?

$ icarus repro.ic
length: 12297829382473034410: file ::= import "file.ic"
length: 12297829382473034410: io ::= import "io.ic"
length: 12297829382473034410: 
length: 12297829382473034410: file.With("repro.ic") open [f: file.File] {
length: 12297829382473034410:   file.Lines(f) each [line: []char] {
length: 12297829382473034410:     io.Print("length: ", line.length, ": ", line)
length: 12297829382473034410:   }
length: 12297829382473034410: }
length: 12297829382473034410:
asoffer commented 2 years ago

Yes, we write 0xAA bytes in debug mode into memory that would be uninitialized in opt-mode, so this is a bug in the IR-generation. We're likely reading the register holding the length but never wrote to it.

To clarify, it's reading the file correctly just the length is wrong? Meaning the call to printf("%*s", ...) likely is getting lucky regarding null terminators.

perimosocordiae commented 2 years ago

Yup, the printing must be hitting the null byte and stopping, rather than trying to print all 0xAAAA... bytes.

perimosocordiae commented 2 years ago

This bug is relatively new, by the way, because the length was initialized properly back when I wrote my day 9 advent solution. I suspect it popped up in the last week or two's changes.