Fix possible uninitialized var in memline.c #12599
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.