Potential null pointer dereference in find_best_size()
@afn
Submitted by Tony Novak Assigned to Desktop Maintainers
Link to original bug (#795075)
Description
Created attachment 370658 Eliminate arbitrary constant
With gcc 7.3.1, gnome-desktop fails to compile with:
gnome-bg-slide-show.c:482:13: error: potential null pointer dereference [-Werror=null-dereference] return best->file; ~~~~^~~~~~
Reading the code, this error appears to be correct. There are two possible ways this could lead to a null pointer dereference:
-
The passed-in aspect ratio is greater than 10000. This could be avoided by having a boolean flag indicating that distance has not yet been initialized, rather than using the arbitrary constant 10000.0. See attached patch.
-
sizes is empty. It's unclear whether this can actually happen in practice, but what's the expected behavior of this function if it is empty?
Patch 370658, "Eliminate arbitrary constant":
eliminate-arbitrary-constant.patch
Version: git master