Christian wrote:
> So my gcc 12.2 started complaining about possibly using an uninitialized
> variable eof:
> ,----
> | fileio.c: In function ‘readfile’:
> | fileio.c:221:17: warning: ‘eof’ may be used uninitialized
> [-Wmaybe-uninitialized]
> | 221 | int eof;
> | | ^~~
> `----
>
> It is currently only initialized in the `if (read_buffer)` case but
> not in the else clause. There is the following code:
>
> if (read_buffer)
> eof = FALSE;
> else [1]
> {
> if (filesize == 0)
> [...]
> else if (filesize > 0 ... [4]
> {
> [...]
> if (curbuf->b_cryptstate->method_nr == CRYPT_M_SOD
> && !eof && may_need_lseek) [3]
> {
> [...]
>
> }
> }
> eof = size; [2]
>
> In the `else` condition [1], eof will only be initialized at [2],
> while it looks like it may be used at [3].
>
> So technically, the `eof` variable could be accessed uninitialized in
> the else if case [4]. This can not happen, because filesize is
> initialized to zero, so Vim cannot run into this case in practice and
> after the first loop, eof will be initialized.
>
> However, I think it's worth it, to move the initialization of the
> `eof` variable to the beginning of the function and don't init it in
> both branches of the if/else condition and also also do not depend on
> the implicit initialization of the filesize variable.
My idea to move the declaration inside the loop does not appear to work
well. "make test_crypt" prompts for a key several times, and eventually
allocated memory is corrupted. Moving the declaration back to the start
of the function fixes most of this.
There still is one prompt for a key though. Hmm, I noticed before that
"eof" is used temporarily to store "size", which is confusing. When I
use a separate variable for that then it works better. Not sure why,
perhaps because "eof" is int and "size" is long?
--
hundred-and-one symptoms of being an internet addict:
187. You promise yourself that you'll only stay online for another
15 minutes...at least once every hour.
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/20230617135929.23FAB1C1241%40moolenaar.net.