Skip to content

Refactor parse_number_range to avoid spurious uninitialized warning #6017

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

Merged
merged 1 commit into from
Apr 7, 2021

Conversation

tautschnig
Copy link
Collaborator

g++-7 -O3 spuriously warned that begin_range was accessed without being
initialized:

../src/util/format_number_range.cpp:102:5: error: ‘*((void*)& begin_range +4)’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
     for(unsigned i = *begin_range; i < *number; ++i)
     ^~~
../src/util/format_number_range.cpp:121:23: note: ‘*((void*)& begin_range +4)’ was declared here
   optionalt<unsigned> begin_range;
                       ^~~~~~~~~~~
cc1plus: all warnings being treated as errors

Although optionalt may seem a bit more beautiful, it's perfectly
possible to implement parse_number_range without any use of optionalt.

  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

g++-7 -O3 spuriously warned that begin_range was accessed without being
initialized:
```
../src/util/format_number_range.cpp:102:5: error: ‘*((void*)& begin_range +4)’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
     for(unsigned i = *begin_range; i < *number; ++i)
     ^~~
../src/util/format_number_range.cpp:121:23: note: ‘*((void*)& begin_range +4)’ was declared here
   optionalt<unsigned> begin_range;
                       ^~~~~~~~~~~
cc1plus: all warnings being treated as errors
```
Although optionalt may seem a bit more beautiful, it's perfectly
possible to implement parse_number_range without any use of optionalt.
@tautschnig tautschnig force-pushed the parse_number_range branch from f1b337e to ca6f109 Compare April 7, 2021 10:39
@tautschnig tautschnig self-assigned this Apr 7, 2021
@codecov
Copy link

codecov bot commented Apr 7, 2021

Codecov Report

Merging #6017 (ca6f109) into develop (36151cf) will decrease coverage by 0.09%.
The diff coverage is 97.50%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #6017      +/-   ##
===========================================
- Coverage    74.23%   74.13%   -0.10%     
===========================================
  Files         1444     1444              
  Lines       157309   157322      +13     
===========================================
- Hits        116781   116637     -144     
- Misses       40528    40685     +157     
Impacted Files Coverage Δ
jbmc/src/java_bytecode/java_bytecode_typecheck.cpp 75.00% <ø> (ø)
..._bytecode_convert_class/convert_abstract_class.cpp 100.00% <ø> (ø)
...va_bytecode_convert_method/convert_initalizers.cpp 100.00% <ø> (ø)
...ambdas/java_bytecode_parse_lambda_method_table.cpp 100.00% <ø> (ø)
...va_bytecode/java_replace_nondet/replace_nondet.cpp 83.33% <ø> (ø)
src/ansi-c/gcc_types.cpp 88.37% <ø> (ø)
src/goto-instrument/cover.cpp 83.42% <ø> (ø)
src/goto-instrument/goto_program2code.cpp 69.14% <ø> (ø)
src/goto-programs/json_goto_trace.cpp 81.74% <ø> (ø)
src/linking/static_lifetime_init.cpp 95.89% <ø> (ø)
... and 12 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c7b4d21...ca6f109. Read the comment docs.

@tautschnig tautschnig merged commit ab404f6 into diffblue:develop Apr 7, 2021
@tautschnig tautschnig deleted the parse_number_range branch April 7, 2021 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants