Re: [PATCH 3/4] ref-filter: merge get_obj and get_object
- From
SZEDER Gábor <szeder.dev@gmail.com>
- Date
- Jul 10, 2018, 10:29 UTC
- Message-ID
- <20180710102937.12499-1-szeder.dev@gmail.com>
- In-Reply-To
- <nycvar.QRO.7.76.6.1807101115570.75@tvgsbejvaqbjf.bet>
Show 25 quoted lines
> This causes GCC to complain thusly:
>
>
> ```
> 2018-07-10T04:59:38.6368270Z ref-filter.c:1477:6: error: variable 'eaten' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
> 2018-07-10T04:59:38.6468620Z if (oi->info.contentp) {
> 2018-07-10T04:59:38.6568710Z ^~~~~~~~~~~~~~~~~
> 2018-07-10T04:59:38.6669970Z ref-filter.c:1489:7: note: uninitialized use occurs here
> 2018-07-10T04:59:38.6774240Z if (!eaten)
> 2018-07-10T04:59:38.6874860Z ^~~~~
> 2018-07-10T04:59:38.6976740Z ref-filter.c:1477:2: note: remove the 'if' if its condition is always true
> 2018-07-10T04:59:38.7072330Z if (oi->info.contentp) {
> 2018-07-10T04:59:38.7172760Z ^~~~~~~~~~~~~~~~~~~~~~~
> 2018-07-10T04:59:38.7274040Z ref-filter.c:1466:11: note: initialize the variable 'eaten' to silence this warning
> 2018-07-10T04:59:38.7374670Z int eaten;
> 2018-07-10T04:59:38.7474870Z ^
> 2018-07-10T04:59:38.7575690Z = 0
> ```
>
> (See
> https://mseng.visualstudio.com/VSOnline/_build/results?buildId=6640204&view=logs
> for details)
>
> I think that GCC is correct, and at the same time, it isn't. Because it
> does not matter whether `eaten` is uninitialized here: It's undefined behaviour; 'eaten' is int, and an int may have padding bits and trap representations.
> if it is, then > `buf` is NULL, and the `free(buf);` call does nothing in particular.