44dd2c6e86
Imagine a constructor like this: int object_new(void **out) { void *my_object; int r; ... r = ioctl(...); if (r < 0) return -errno; ... *out = my_object; return 0; } We have a lot of those in systemd. If you now call those, gcc might inline the call and optimize it. However, gcc cannot know that "errno" is negative if "r" is. Therefore, a caller like this will produce warnings: r = object_new(&obj); if (r < 0) return r; obj->xyz = "foobar"; In case the ioctl in the constructor fails, gcc might assume "errno" is 0 and thus the error-handling is not triggered. Therefore, "obj" is uninitialized, but accessed. Gcc will warn about that. The new negative_errno() helper can be used to mitigate those warnings. The helper is guaranteed to return a negative integer. Furthermore, it spills out runtime warnings if "errno" is non-negative. Instead of returning "-errno", you can use: return negative_errno(); gcc will no longer assume that this can return >=0, thus, it will not warn about it. Use this new helper in libsystemd-terminal to fix some grdev-drm warnings. |
||
---|---|---|
.. | ||
evcat.c | ||
grdev-drm.c | ||
grdev-internal.h | ||
grdev.c | ||
grdev.h | ||
idev-evdev.c | ||
idev-internal.h | ||
idev-keyboard.c | ||
idev.c | ||
idev.h | ||
modeset.c | ||
subterm.c | ||
sysview-internal.h | ||
sysview.c | ||
sysview.h | ||
term-charset.c | ||
term-internal.h | ||
term-page.c | ||
term-parser.c | ||
term-screen.c | ||
term-wcwidth.c | ||
term.h | ||
test-term-page.c | ||
test-term-parser.c | ||
test-unifont.c | ||
unifont-def.h | ||
unifont-glyph-array.bin | ||
unifont.c | ||
unifont.h | ||
unifont.hex |