Skip to content

Commit 22773e5

Browse files
[libc] Fix condition ordering in scanf (#80083)
The inf and nan string index bounds checks were after the index was being used. This patch moves the index usage to the end of the condition. Fixes #79988
1 parent ebe8733 commit 22773e5

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

libc/src/stdio/scanf_core/float_converter.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ int convert_float(Reader *reader, const FormatSection &to_conv) {
5757
if (to_lower(cur_char) == inf_string[0]) {
5858
size_t inf_index = 0;
5959

60-
for (; to_lower(cur_char) == inf_string[inf_index] &&
61-
inf_index < sizeof(inf_string) && out_str.length() < max_width;
60+
for (; inf_index < sizeof(inf_string) && out_str.length() < max_width &&
61+
to_lower(cur_char) == inf_string[inf_index];
6262
++inf_index) {
6363
if (!out_str.append(cur_char)) {
6464
return ALLOCATION_FAILURE;
@@ -80,8 +80,8 @@ int convert_float(Reader *reader, const FormatSection &to_conv) {
8080
if (to_lower(cur_char) == nan_string[0]) {
8181
size_t nan_index = 0;
8282

83-
for (; to_lower(cur_char) == nan_string[nan_index] &&
84-
nan_index < sizeof(nan_string) && out_str.length() < max_width;
83+
for (; nan_index < sizeof(nan_string) && out_str.length() < max_width &&
84+
to_lower(cur_char) == nan_string[nan_index];
8585
++nan_index) {
8686
if (!out_str.append(cur_char)) {
8787
return ALLOCATION_FAILURE;

0 commit comments

Comments
 (0)