Closed InKryption closed 1 year ago
What is UB?
It stands for Undefined Behavior. In zig, assigning the undefined
literal is equivalent to not initializing whatever you're assigning it to, meaning it probably has some meaningless garbage value - except in debug mode, where it assigns screaming bytes (0xAA
) as a debugging convenience.
In this case, when you failed to pass -Dalgorithm=<algo>
, it caused the length of the slice to almost never match against that of any of the strings that were compared against, which meant it wouldn't try to access the garbage pointer location, which would have caused a segfault otherwise.
TLDR: you shouldn't read values that haven't been initialized, which is what undefined
here signifies.
Using
undefined
here can trigger UB - insteadreturn
early.