[hatari-devel] fixing errors reported by GCC 10 -fanalyzer |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/hatari-devel Archives
]
Hi
I compiled Hatari with GCC10 -fanalyzer to give it a try.
It reports some possible NULL pointer after malloc, as well as some
other double free.
It's possible some reported errors are false positives, because GCC
can't analyze the full code flow depending on how Hatari will really run
(for example in debug/*c, many errors are reported, not sure they're
really errors)
Still, if people want to compile with -fanalyzer, maybe we can spot some
issues that need fixing.
I fixed a few mallocs not testing NULL after return.
In ide.c, some fixes are needed here :
s->io_buffer = malloc(MAX_MULT_SECTORS *
MAX_SECTOR_SIZE + 4);
assert(s->io_buffer);
[...]
hd_table[i] = malloc(sizeof(BlockDriverState));
assert(hd_table[i]);
The problem is that assert can be disabled completely depending on
compilation flags, so NULL won't be tested in these 2 cases. ide_init2()
and Ide_Init() return void, maybe they should return true or false,
false if init fails ?
Similar assert should be changed in statusbar.c :
void Statusbar_AddMessage(const char *msg, Uint32 msecs)
....
item = calloc(1, sizeof(msg_item_t));
assert(item);
NOTE : assert() is used in several places ; as the condition/error
tested by assert() can also happen when assert is compiled to no-code
"{}", maybe assert() should be replaced by proper printf+exit (or return
if possible) ?
Nicolas