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

Fix possible uninitialized var in memline.c #12599

Closed
wants to merge 1 commit into from

Conversation

chrisbra
Copy link
Member

With gcc on msys64:
,----
| $ gcc --version
| gcc.exe (Rev6, Built by MSYS2 project) 13.1.0
| Copyright (C) 2023 Free Software Foundation, Inc. | This is free software; see the source for copying conditions. There is NO | warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. `----

I see the following warning in memline.c:

,----
| memline.c: In function 'adjust_text_props_for_delete': | memline.c:3670:43: warning: 'this_props_len' may be used uninitialized [-Wmaybe-uninitialized]
| 3670 | for (done_this = 0; done_this < this_props_len;
| | ~~~~~~~~~~^~~~~~~~~~~~~~~~
| memline.c:3629:17: note: 'this_props_len' was declared here
| 3629 | int this_props_len;
| | ^~~~~~~~~~~~~~
| In file included from memline.c:45:
| memline.c:3677:56: warning: 'text' may be used uninitialized [-Wmaybe-uninitialized]
| 3677 | mch_memmove(&prop_this, text + textlen + done_this,
| vim.h:1803:66: note: in definition of macro 'mch_memmove'
| 1803 | # define mch_memmove(to, from, len) memmove((char*)(to), (char*)(from), (size_t)(len))
| | ^~~~
| memline.c:3630:18: note: 'text' was declared here
| 3630 | char_u text;
| | ^~~~
| memline.c:3677:56: warning: 'textlen' may be used uninitialized [-Wmaybe-uninitialized]
| 3677 | mch_memmove(&prop_this, text + textlen + done_this,
| | ^
| vim.h:1803:66: note: in definition of macro 'mch_memmove'
| 1803 | # define mch_memmove(to, from, len) memmove((char
)(to), (char*)(from), (size_t)(len))
| | ^~~~
| memline.c:3631:17: note: 'textlen' was declared here
| 3631 | size_t textlen;
| | ^~~~~~~
`----

Interestingly the other warnings go away, after fixing the first one and initializing this_prop_len.

But I think this may be worth it anyhow to fix this warning.

With gcc on msys64:
,----
| $ gcc --version
| gcc.exe (Rev6, Built by MSYS2 project) 13.1.0
| Copyright (C) 2023 Free Software Foundation, Inc.
| This is free software; see the source for copying conditions.  There is NO
| warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
`----

I see the following warning in memline.c:

,----
| memline.c: In function 'adjust_text_props_for_delete':
| memline.c:3670:43: warning: 'this_props_len' may be used uninitialized [-Wmaybe-uninitialized]
|  3670 |             for (done_this = 0; done_this < this_props_len;
|       |                                 ~~~~~~~~~~^~~~~~~~~~~~~~~~
| memline.c:3629:17: note: 'this_props_len' was declared here
|  3629 |     int         this_props_len;
|       |                 ^~~~~~~~~~~~~~
| In file included from memline.c:45:
| memline.c:3677:56: warning: 'text' may be used uninitialized [-Wmaybe-uninitialized]
|  3677 |                 mch_memmove(&prop_this, text + textlen + done_this,
| vim.h:1803:66: note: in definition of macro 'mch_memmove'
|  1803 | # define mch_memmove(to, from, len) memmove((char*)(to), (char*)(from), (size_t)(len))
|       |                                                                  ^~~~
| memline.c:3630:18: note: 'text' was declared here
|  3630 |     char_u      *text;
|       |                  ^~~~
| memline.c:3677:56: warning: 'textlen' may be used uninitialized [-Wmaybe-uninitialized]
|  3677 |                 mch_memmove(&prop_this, text + textlen + done_this,
|       |                                                        ^
| vim.h:1803:66: note: in definition of macro 'mch_memmove'
|  1803 | # define mch_memmove(to, from, len) memmove((char*)(to), (char*)(from), (size_t)(len))
|       |                                                                  ^~~~
| memline.c:3631:17: note: 'textlen' was declared here
|  3631 |     size_t      textlen;
|       |                 ^~~~~~~
`----

Interestingly the other warnings go away, after fixing the first one and
initializing this_prop_len.

But I think this may be worth it anyhow to fix this warning.
@codecov
Copy link

codecov bot commented Jun 26, 2023

Codecov Report

Merging #12599 (57d750a) into master (590aae3) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master   #12599      +/-   ##
==========================================
- Coverage   82.09%   82.08%   -0.01%     
==========================================
  Files         160      160              
  Lines      193658   193659       +1     
  Branches    43482    43482              
==========================================
- Hits       158977   158960      -17     
- Misses      21836    21853      +17     
- Partials    12845    12846       +1     
Flag Coverage Δ
huge-clang-none 82.71% <100.00%> (-0.02%) ⬇️
linux 82.71% <100.00%> (-0.02%) ⬇️
mingw-x64-HUGE 76.61% <ø> (-0.01%) ⬇️
mingw-x86-HUGE 77.07% <ø> (+0.01%) ⬆️
windows 78.20% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/memline.c 80.44% <100.00%> (+<0.01%) ⬆️

... and 9 files with indirect coverage changes

@brammool brammool closed this in a2a90d5 Jun 26, 2023
@chrisbra chrisbra deleted the fix_msys_uninitialized branch June 26, 2023 20:42
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.

None yet

1 participant