misc: fix tons of undefined behavior #720
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
These were discovered during the work on #719.
zig cc
is justclang
but with some more reasonable defaults. One of them is-fsanitize=undefined
by default in debug builds. This results in aSIGTRAP
iflibubsan
is not linked to the executable every time the program encounters undefined behavior at runtime. Linking the undefined behavior sanitizer gives more information about what's going on.It turns out that just turning on a previously booted ship has thousands of instances of undefined behavior before even reaching the dojo. These are mainly of two different kinds: left shifting without the proper casts and unaligned member access of the nock bytecode programs.
This PR fixes all the instances of undefined behavior that are immediately obvious when turning on a fakezod. The fixes consist of adding the proper casts to the left shift operations and padding the members of the
u3n_prog
to be 8 byte aligned. The corresponding loom migration is also provided.Note that I decided to make
burnframe
innock.c
a packed struct to get around the alignment issues it has. Something smarter could be considered in the future.