Open f-saez opened 2 weeks ago
Reproduces with latest nightly build: mojo 2024.6.2005 (6f19fd07).
It is because List[UInt8]
gets constructed to a String
when pass into f.write()
. This constructor requires your list, t1
to have null terminator as last element (t1[-1] == 0
). If you run with mojo -D MOJO_ENABLE_ASSERTIONS
, your code will crash with Assert Error: expected last element of String buffer to be null terminator
.
thanks.
I already add a 0 when I need to write a bunch of bytes.
It also means that one can construct a String with invalid UTF8 code-point (or maybe I was lucky all this time :-) ), but I guess it's another debate.
Do I need to close this bug ?
It also means that one can construct a String with invalid UTF8 code-point (or maybe I was lucky all this time :-) ), but I guess it's another debate.
It seems like the case for me. We are treating last character as the null terminator. For String.__len__()
we are simply returning the buffer size - 1.
Bug description
Hi,
One again, maybe a bug, maybe I've misundertood how file works in Mojo.
Very basic stuff. I insert 8 bytes in a list, I write the list on a file, and then I check the size of the file (should be the size of the list), then I read the file and it should have the same content as the list. trouble is : the last byte is missing
First thing that come to mind is that "write" expect a zero-terminal string and eat the last byte each time I call write. But t1 is not a string and the compiler doesn't raise a single error. "read_bytes" exists but I haven't found "write_bytes"
Steps to reproduce
execute the code provided
System information