New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
printing float value causes fmt to panic #11283
Comments
I looked into this a little bit. The underlying C library on which the Zig code is based performs an out-of-bounds write with the float value in this issue: this line writes to an address before the start of #include <stdbool.h>
#include "errol.h"
int main(void) {
char buf[100] = {};
double val = 1.000000e+37;
int exp = errol3_dtoa(val, buf);
} Compile with This specific issue can be fixed by detecting the underflow and handling it, but the code is pretty opaque and I don't know if that would silently introduce incorrect results in some other cases. |
I consider this an interim workaround/hack until ziglang#1299 is finished. There is a bug in the original C implementation of the errol3 (and errol4) algorithm that can result in undefined behavior or an obviously incorrect result (leading ':' in the output) This change checks for those two problems and uses a slower fallback path if they occur. I can't guarantee that this will always produce the correct result, but since the workaround is only used if the original algorithm is guaranteed to fail, it should never turn a previously-correct result into an incorrect one. Fixes ziglang#11283
I consider this an interim workaround/hack until #1299 is finished. There is a bug in the original C implementation of the errol3 (and errol4) algorithm that can result in undefined behavior or an obviously incorrect result (leading ':' in the output) This change checks for those two problems and uses a slower fallback path if they occur. I can't guarantee that this will always produce the correct result, but since the workaround is only used if the original algorithm is guaranteed to fail, it should never turn a previously-correct result into an incorrect one. Fixes #11283
I consider this an interim workaround/hack until ziglang#1299 is finished. There is a bug in the original C implementation of the errol3 (and errol4) algorithm that can result in undefined behavior or an obviously incorrect result (leading ':' in the output) This change checks for those two problems and uses a slower fallback path if they occur. I can't guarantee that this will always produce the correct result, but since the workaround is only used if the original algorithm is guaranteed to fail, it should never turn a previously-correct result into an incorrect one. Fixes ziglang#11283
Zig Version
0.10.0-dev.768+d811e03fb
Steps to Reproduce
Expected Behavior
Runs.
Actual Behavior
Context
This error was encountered while trying to print values from a file in the standard library.
zig/lib/std/fmt/errol/lookup.zig
Line 277 in d298719
The highlighted line corresponds to this precise value.
It might be worth testing the fix against the whole contents of
lookup_table
.The text was updated successfully, but these errors were encountered: