Skip to content
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

libc/src/stdio/scanf_core/float_converter.cpp: 2 * sanity check in wrong place ? #79988

Closed
dcb314 opened this issue Jan 30, 2024 · 1 comment · Fixed by #80083
Closed

libc/src/stdio/scanf_core/float_converter.cpp: 2 * sanity check in wrong place ? #79988

dcb314 opened this issue Jan 30, 2024 · 1 comment · Fixed by #80083
Assignees

Comments

@dcb314
Copy link

dcb314 commented Jan 30, 2024

Static analyser cppcheck says

libc/src/stdio/scanf_core/float_converter.cpp:60:44: style: Array index 'inf_index' is used before limits check. [arrayIndexThenCheck]

Source code is

for (; to_lower(cur_char) == inf_string[inf_index] &&
       inf_index < sizeof(inf_string) && out_str.length() < max_width;
     ++inf_index) {

Suggest move sanity check to before use.

ibc/src/stdio/scanf_core/float_converter.cpp:83:44: style: Array index 'nan_index' is used before limits check. [arrayIndexThenCheck]

Duplicate.

@github-actions github-actions bot added the libc label Jan 30, 2024
@michaelrj-google michaelrj-google self-assigned this Jan 30, 2024
michaelrj-google added a commit to michaelrj-google/llvm-project that referenced this issue Jan 31, 2024
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 llvm#79988
@michaelrj-google
Copy link
Contributor

Thanks for finding this and filing an issue, I've created a patch to fix it: #80083.

michaelrj-google added a commit that referenced this issue Jan 31, 2024
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
carlosgalvezp pushed a commit to carlosgalvezp/llvm-project that referenced this issue Feb 1, 2024
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 llvm#79988
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants