Skip to content

Commit b3a1134

Browse files
Fix fread segfault from faulty assumption on compilers (#7200)
* segfault fixed (that I introduced, tbf) * readded default value to object subnormal * added explaination comment * "segfault" to "segfaults" * refine comment --------- Co-authored-by: Michael Chirico <[email protected]>
1 parent c8bbb58 commit b3a1134

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/fread.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -927,10 +927,13 @@ static void parse_double_hexadecimal(FieldParseContext *ctx)
927927
if (neg) ch++;
928928
else if (*ch == '+') ch++;
929929

930-
const bool subnormal = ch[2] == '0';
930+
bool subnormal = false;
931931

932+
// Important!
933+
// Keep in mind that only ch[0] is guaranteed to be mapped.
934+
// Rearranging these checks (e.g. to make 'subnormal' const) will lead to segfaults in rare cases.
932935
if (ch[0] == '0' && (ch[1] == 'x' || ch[1] == 'X') &&
933-
(ch[2] == '1' || (subnormal)) && ch[3] == '.') {
936+
(ch[2] == '1' || (subnormal = (ch[2] == '0'))) && ch[3] == '.') {
934937
ch += 4;
935938
uint64_t acc = 0;
936939
uint8_t digit;

0 commit comments

Comments
 (0)