At patchlevel 8.2.3526: warning -Wmaybe-uninitialized in gui_gtk_x11.c

11 views
Skip to first unread message

Tony Mechelynck

unread,
Oct 16, 2021, 7:21:20 PM10/16/21
to Bram Moolenaar, vim_dev
In GTK builds (here GTK3):

gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK -pthread
-I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0
-I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0
-I/usr/lib64/dbus-1.0/include -I/usr/include/gtk-3.0
-I/usr/include/gio-unix-2.0 -I/usr/include/libxkbcommon
-I/usr/include/wayland -I/usr/include/cairo -I/usr/include/pango-1.0
-I/usr/include/fribidi -I/usr/include/harfbuzz -I/usr/include/atk-1.0
-I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2
-I/usr/include/libpng16 -I/usr/include/gdk-pixbuf-2.0
-I/usr/include/libmount -I/usr/include/blkid -I/usr/include/glib-2.0
-I/usr/lib64/glib-2.0/include -O2 -fno-strength-reduce -Wall
-Wno-deprecated-declarations -D_REENTRANT -U_FORTIFY_SOURCE
-D_FORTIFY_SOURCE=1 -o objects/gui_gtk_x11.o gui_gtk_x11.c
gui_gtk_x11.c: In function ‘gui_gtk2_draw_string’:
gui_gtk_x11.c:5749:13: warning: ‘should_need_pango’ may be used
uninitialized in this function [-Wmaybe-uninitialized]
len_sum += gui_gtk2_draw_string_ext(row, col + len_sum,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cs, slen, flags, needs_pango);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Best regards,
Tony.

Dusan Popovic

unread,
Oct 16, 2021, 7:33:37 PM10/16/21
to vim...@googlegroups.com, Bram Moolenaar
On 17/10/21, Tony Mechelynck wrote:
> gui_gtk_x11.c:5749:13: warning: ‘should_need_pango’ may be used

I just read code again and I don't see any path to reach assignment that
happens later on before variable gets properly set. Of course
initializing should_need_pango won't hurt but I don't think it helps.
Did I miss some edge case?
signature.asc

Tony Mechelynck

unread,
Oct 16, 2021, 9:11:03 PM10/16/21
to vim_dev, Bram Moolenaar
I suppose the edge case you missed is that gcc isn't as clever as you are.

Best regards,
Tony.

Dusan Popovic

unread,
Oct 17, 2021, 4:46:33 AM10/17/21
to vim...@googlegroups.com, Bram Moolenaar
On 17/10/21, Tony Mechelynck wrote:
> I suppose the edge case you missed is that gcc isn't as clever as you are.

Of course I'll make sure to include -Wmaybe-uninitialized next time, too
early to look at the code so I am not sure if it is already used or I
need to include it additionally. Good to clear any warning so thanks for
the tip.

Cheers,
Dusan
signature.asc

Bram Moolenaar

unread,
Oct 17, 2021, 6:37:51 AM10/17/21
to vim...@googlegroups.com, Tony Mechelynck
The error is confusing, because it is at the line where needs_pango is
used. But needs_pango got the value of should_need_pango further down,
apparently the not-initialized mark is transfered between the variables.

Gcc doesn't know that the while is always making at least one loop.

--
hundred-and-one symptoms of being an internet addict:
175. You send yourself e-mail before you go to bed to remind you
what to do when you wake up.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Dusan Popovic

unread,
Oct 17, 2021, 6:51:57 AM10/17/21
to vim...@googlegroups.com, Tony Mechelynck
There are two nested while loops with seemingly different math, I
believe that's what made Gcc stumble: `while (cs < s + len)` and `while
(slen < (len - byte_sum))`. Variable is set in inner loop while outer
loop needs it. Human eye can distinguish that we can't enter outer loop
without entering inner one, at least once, but I can understand how that
may look to Gcc. Will take care with next PR, thanks.

Best,
Dusan
signature.asc
Reply all
Reply to author
Forward
0 new messages