Conditional jump or move depends on uninitialised value(s)

Valgrind always report "Conditional jump or move depends on
uninitialised value(s) " when I press some key to exit the event loop
for application based on SDL2.

Is valgrind wrong? Or is there problem in SDL?

The attachment is an lame example named sdlbug.c (without checking the
return value of SDL_Init).
Link sdlbug.c with SDL2 rev 6303 on 32bits gentoo linux. Run the
application with valgrind:

valgrind --leak-check=full --track-origins=yes ./sdlbug

When I press ESCAPE, the application terminates and valgrind print
errors like this:

==3494== Memcheck, a memory error detector
==3494== Copyright © 2002-2011, and GNU GPL’d, by Julian Seward et al.
==3494== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==3494== Command: ./sdlbug
==3494==
==3494== Conditional jump or move depends on uninitialised value(s)
==3494== at 0x4066977: SDL_SendFingerDown (SDL_touch.c:353)
==3494== by 0x40D5C90: X11_PumpEvents (SDL_x11events.c:601)
==3494== by 0x4061063: SDL_PumpEvents (SDL_events.c:303)
==3494== by 0x4061599: SDL_WaitEventTimeout (SDL_events.c:336)
==3494== by 0x4061674: SDL_PollEvent (SDL_events.c:318)
==3494== by 0x804865D: main (sdlbug.c:14)
==3494== Uninitialised value was created by a stack allocation
==3494== at 0x40DA8B1: X11_InitTouch (SDL_x11touch.c:37)
==3494==
==3494==
==3494== HEAP SUMMARY:
==3494== in use at exit: 159,398 bytes in 937 blocks
==3494== total heap usage: 6,292 allocs, 5,355 frees, 3,726,924
bytes allocated
==3494==
==3494== 4 bytes in 1 blocks are definitely lost in loss record 12 of 508
==3494== at 0x4027984: operator new(unsigned int) (vg_replace_malloc.c:282)
==3494== by 0x534B08E: ???
==3494== by 0x53327B1: ???
==3494== by 0x53479CA: ???
==3494== by 0x5347CB0: ???
==3494== by 0x5354ADF: ???
==3494== by 0x4A0EB50: ???
==3494== by 0x400EBE6: call_init (dl-init.c:70)
==3494== by 0x400ED08: _dl_init (dl-init.c:134)
==3494== by 0x4012E79: dl_open_worker (dl-open.c:478)
==3494== by 0x400E7F6: _dl_catch_error (dl-error.c:178)
==3494== by 0x40125A7: _dl_open (dl-open.c:569)
==3494==
==3494== 12 bytes in 1 blocks are definitely lost in loss record 30 of 508
==3494== at 0x4027984: operator new(unsigned int) (vg_replace_malloc.c:282)
==3494== by 0x4DDB510: ???
==3494== by 0x53327B1: ???
==3494== by 0x4DD7BE3: ???
==3494== by 0x4DD7C6C: ???
==3494== by 0x4DD8484: ???
==3494== by 0x4E3B178: ???
==3494== by 0x4D0728E: ???
==3494== by 0x4CF41C7: ???
==3494== by 0x4EEE535: ???
==3494== by 0x4EEEC88: ???
==3494== by 0x4CD43E9: ???
==3494==
==3494== 14 bytes in 2 blocks are definitely lost in loss record 35 of 508
==3494== at 0x4026EE1: malloc (vg_replace_malloc.c:263)
==3494== by 0x47439CA: _XimEncodeString (in /usr/lib/libX11.so.6.3.0)
==3494== by 0x4742A14: _XimEncodeLocalICAttr (in /usr/lib/libX11.so.6.3.0)
==3494== by 0x4743C25: _XimSetICValueData (in /usr/lib/libX11.so.6.3.0)
==3494== by 0x473EBBA: _XimLocalCreateIC (in /usr/lib/libX11.so.6.3.0)
==3494== by 0x4722F2B: XCreateIC (in /usr/lib/libX11.so.6.3.0)
==3494== by 0x40DC4DB: SetupWindowData (SDL_x11window.c:109)
==3494== by 0x40DCA09: X11_CreateWindow (SDL_x11window.c:552)
==3494== by 0x40C0A96: SDL_CreateWindow (SDL_video.c:1199)
==3494== by 0x40C0F6F: SDL_VideoInit (SDL_video.c:174)
==3494== by 0x4037FFB: SDL_InitSubSystem (SDL.c:74)
==3494== by 0x4038064: SDL_Init (SDL.c:150)
==3494==
==3494== 14 bytes in 2 blocks are definitely lost in loss record 36 of 508
==3494== at 0x4026EE1: malloc (vg_replace_malloc.c:263)
==3494== by 0x47439CA: _XimEncodeString (in /usr/lib/libX11.so.6.3.0)
==3494== by 0x4742A14: _XimEncodeLocalICAttr (in /usr/lib/libX11.so.6.3.0)
==3494== by 0x4743C25: _XimSetICValueData (in /usr/lib/libX11.so.6.3.0)
==3494== by 0x473EBBA: _XimLocalCreateIC (in /usr/lib/libX11.so.6.3.0)
==3494== by 0x4722F2B: XCreateIC (in /usr/lib/libX11.so.6.3.0)
==3494== by 0x40DC4DB: SetupWindowData (SDL_x11window.c:109)
==3494== by 0x40DCA09: X11_CreateWindow (SDL_x11window.c:552)
==3494== by 0x40C0A96: SDL_CreateWindow (SDL_video.c:1199)
==3494== by 0x8048620: main (sdlbug.c:7)
==3494==
==3494== 20 (12 direct, 8 indirect) bytes in 1 blocks are definitely
lost in loss record 138 of 508
==3494== at 0x4027984: operator new(unsigned int) (vg_replace_malloc.c:282)
==3494== by 0x532D933: ???
==3494== by 0x4CE9530: ???
==3494== by 0x4CF3905: ???
==3494== by 0x4CF3AD2: ???
==3494== by 0x4CA1287: ???
==3494== by 0x4CA1322: ???
==3494== by 0x4A53868: ???
==3494== by 0x4A6B718: ???
==3494== by 0x4A14459: ???
==3494== by 0x4A10BA2: ???
==3494== by 0x4A10C03: ???
==3494==
==3494== 36 (12 direct, 24 indirect) bytes in 1 blocks are definitely
lost in loss record 298 of 508
==3494== at 0x4027984: operator new(unsigned int) (vg_replace_malloc.c:282)
==3494== by 0x4DFE523: ???
==3494== by 0x53327B1: ???
==3494== by 0x5344651: ???
==3494== by 0x4CE19AA: ???
==3494== by 0x4CE1AE5: ???
==3494== by 0x4CDC7D9: ???
==3494== by 0x4CD427E: ???
==3494== by 0x4CD4559: ???
==3494== by 0x4CE95BE: ???
==3494== by 0x4CF3905: ???
==3494== by 0x4CF3AD2: ???
==3494==
==3494== 36 (12 direct, 24 indirect) bytes in 1 blocks are definitely
lost in loss record 299 of 508
==3494== at 0x4027984: operator new(unsigned int) (vg_replace_malloc.c:282)
==3494== by 0x4DFE523: ???
==3494== by 0x53327B1: ???
==3494== by 0x5298BEA: ???
==3494== by 0x528B036: ???
==3494== by 0x528D6E7: ???
==3494== by 0x5354ADF: ???
==3494== by 0x4A0EB50: ???
==3494== by 0x400EBE6: call_init (dl-init.c:70)
==3494== by 0x400ED08: _dl_init (dl-init.c:134)
==3494== by 0x4012E79: dl_open_worker (dl-open.c:478)
==3494== by 0x400E7F6: _dl_catch_error (dl-error.c:178)
==3494==
==3494== 64 (40 direct, 24 indirect) bytes in 1 blocks are definitely
lost in loss record 321 of 508
==3494== at 0x4027984: operator new(unsigned int) (vg_replace_malloc.c:282)
==3494== by 0x4CD2816: ???
==3494== by 0x53327B1: ???
==3494== by 0x4CD444E: ???
==3494== by 0x4CD4559: ???
==3494== by 0x4CE95BE: ???
==3494== by 0x4CF3905: ???
==3494== by 0x4CF3AD2: ???
==3494== by 0x4CA1287: ???
==3494== by 0x4CA1322: ???
==3494== by 0x4A53868: ???
==3494== by 0x4A6B718: ???
==3494==
==3494== 112 bytes in 1 blocks are definitely lost in loss record 351 of 508
==3494== at 0x4025BE5: calloc (vg_replace_malloc.c:566)
==3494== by 0x48A79D8: driswCreateScreen (drisw_glx.c:626)
==3494== by 0x488543E: __glXInitialize (glxext.c:784)
==3494== by 0x4881D6A: GetGLXPrivScreenConfig (glxcmds.c:176)
==3494== by 0x4883056: glXChooseVisual (glxcmds.c:1234)
==3494== by 0x40D9D04: X11_GL_InitExtensions (SDL_x11opengl.c:434)
==3494== by 0x40DA3D6: X11_GL_LoadLibrary (SDL_x11opengl.c:186)
==3494== by 0x40BDFEF: SDL_GL_LoadLibrary (SDL_video.c:2135)
==3494== by 0x40C09C9: SDL_CreateWindow (SDL_video.c:1167)
==3494== by 0x40C0F6F: SDL_VideoInit (SDL_video.c:174)
==3494== by 0x4037FFB: SDL_InitSubSystem (SDL.c:74)
==3494== by 0x4038064: SDL_Init (SDL.c:150)
==3494==
==3494== 190 (100 direct, 90 indirect) bytes in 1 blocks are
definitely lost in loss record 374 of 508
==3494== at 0x4026EE1: malloc (vg_replace_malloc.c:263)
==3494== by 0x4065EC2: SDL_AddTouch (SDL_touch.c:120)
==3494== by 0x40DABD4: X11_InitTouch (SDL_x11touch.c:90)
==3494== by 0x40DB4CF: X11_VideoInit (SDL_x11video.c:367)
==3494== by 0x40C0E66: SDL_VideoInit (SDL_video.c:507)
==3494== by 0x4037FFB: SDL_InitSubSystem (SDL.c:74)
==3494== by 0x4038064: SDL_Init (SDL.c:150)
==3494== by 0x80485EC: main (sdlbug.c:6)
==3494==
==3494== 8,439 (4 direct, 8,435 indirect) bytes in 1 blocks are
definitely lost in loss record 505 of 508
==3494== at 0x4027984: operator new(unsigned int) (vg_replace_malloc.c:282)
==3494== by 0x5298E5E: ???
==3494== by 0x53327B1: ???
==3494== by 0x52973CA: ???
==3494== by 0x528B02A: ???
==3494== by 0x528D6E7: ???
==3494== by 0x5354ADF: ???
==3494== by 0x4A0EB50: ???
==3494== by 0x400EBE6: call_init (dl-init.c:70)
==3494== by 0x400ED08: _dl_init (dl-init.c:134)
==3494== by 0x4012E79: dl_open_worker (dl-open.c:478)
==3494== by 0x400E7F6: _dl_catch_error (dl-error.c:178)
==3494==
==3494== 109,189 (28 direct, 109,161 indirect) bytes in 1 blocks are
definitely lost in loss record 508 of 508
==3494== at 0x4025BE5: calloc (vg_replace_malloc.c:566)
==3494== by 0x4CA1313: ???
==3494== by 0x4A53868: ???
==3494== by 0x4A6B718: ???
==3494== by 0x4A14459: ???
==3494== by 0x4A10BA2: ???
==3494== by 0x4A10C03: ???
==3494== by 0x4A10C3D: ???
==3494== by 0x48A797B: drisw_create_context (drisw_glx.c:404)
==3494== by 0x4882552: CreateContext (glxcmds.c:276)
==3494== by 0x48837D1: glXCreateContext (glxcmds.c:381)
==3494== by 0x40D9DF5: X11_GL_InitExtensions (SDL_x11opengl.c:278)
==3494==
==3494== LEAK SUMMARY:
==3494== definitely lost: 364 bytes in 14 blocks
==3494== indirectly lost: 117,766 bytes in 456 blocks
==3494== possibly lost: 0 bytes in 0 blocks
==3494== still reachable: 41,268 bytes in 467 blocks
==3494== suppressed: 0 bytes in 0 blocks
==3494== Reachable blocks (those to which a pointer was found) are not shown.
==3494== To see them, rerun with: --leak-check=full --show-reachable=yes
==3494==
==3494== For counts of detected and suppressed errors, rerun with: -v
==3494== ERROR SUMMARY: 13 errors from 13 contexts (suppressed: 194 from 13)

Check the attachment for the lame code sdlbug.c (without checking
return value of SDL_Init).

Thanks.
-------------- next part --------------
A non-text attachment was scrubbed…
Name: sdlbug.c
Type: text/x-csrc
Size: 645 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20120316/1ae9c420/attachment.c

http://hg.libsdl.org/SDL/file/6bb657898f55/src/events/SDL_touch.c

Line 130-146 seems initialize the SDL_Touch structure’s various fields.

130 http://hg.libsdl.org/SDL/file/6bb657898f55/src/events/SDL_touch.c#l130
SDL_touchPads[index]->focus = 0;

131 http://hg.libsdl.org/SDL/file/6bb657898f55/src/events/SDL_touch.c#l131
SDL_touchPads[index]->name = SDL_malloc((length + 2) *
sizeof(char));

132 http://hg.libsdl.org/SDL/file/6bb657898f55/src/events/SDL_touch.c#l132
SDL_strlcpy(SDL_touchPads[index]->name, name, length + 1);

133 http://hg.libsdl.org/SDL/file/6bb657898f55/src/events/SDL_touch.c#l133

134 http://hg.libsdl.org/SDL/file/6bb657898f55/src/events/SDL_touch.c#l134
SDL_touchPads[index]->num_fingers = 0;

135 http://hg.libsdl.org/SDL/file/6bb657898f55/src/events/SDL_touch.c#l135
SDL_touchPads[index]->max_fingers = 1;

136 http://hg.libsdl.org/SDL/file/6bb657898f55/src/events/SDL_touch.c#l136
SDL_touchPads[index]->fingers = (SDL_Finger *)
SDL_malloc(sizeof(SDL_Finger
));

137 http://hg.libsdl.org/SDL/file/6bb657898f55/src/events/SDL_touch.c#l137
SDL_touchPads[index]->fingers[0] = NULL;

138 http://hg.libsdl.org/SDL/file/6bb657898f55/src/events/SDL_touch.c#l138
SDL_touchPads[index]->buttonstate = 0;

139 http://hg.libsdl.org/SDL/file/6bb657898f55/src/events/SDL_touch.c#l139
SDL_touchPads[index]->relative_mode = SDL_FALSE;

140 http://hg.libsdl.org/SDL/file/6bb657898f55/src/events/SDL_touch.c#l140
SDL_touchPads[index]->flush_motion = SDL_FALSE;

141 http://hg.libsdl.org/SDL/file/6bb657898f55/src/events/SDL_touch.c#l141

142 http://hg.libsdl.org/SDL/file/6bb657898f55/src/events/SDL_touch.c#l142
SDL_touchPads[index]->xres = (1<<(16-1));

143 http://hg.libsdl.org/SDL/file/6bb657898f55/src/events/SDL_touch.c#l143
SDL_touchPads[index]->yres = (1<<(16-1));

144 http://hg.libsdl.org/SDL/file/6bb657898f55/src/events/SDL_touch.c#l144
SDL_touchPads[index]->pressureres = (1<<(16-1));

then Line 353 (valgrind)

if(xin < touch->x_min || yin < touch->y_min) return 0; //should defer
if only a partial input

I don’t see where touch->x_min and touch->y_min get initialized, so you may
have a legitimate bug here. The easiest way to tell (if you’re compiling
from source) is to modify SDL_touch.c around line 145 and add something
like SDL_touchPads[index]->x_min = SDL_touchPads[index]->y_min = 0; and see
if the Valgrind message goes away. That isn’t to say that is a proper fix
by any means – but it would definitely tell if those fields were
uninitialized and used.On Fri, Mar 16, 2012 at 8:54 AM, Spark Around wrote:

Valgrind always report "Conditional jump or move depends on
uninitialised value(s) " when I press some key to exit the event loop
for application based on SDL2.

Is valgrind wrong? Or is there problem in SDL?

The attachment is an lame example named sdlbug.c (without checking the
return value of SDL_Init).
Link sdlbug.c with SDL2 rev 6303 on 32bits gentoo linux. Run the
application with valgrind:

valgrind --leak-check=full --track-origins=yes ./sdlbug

When I press ESCAPE, the application terminates and valgrind print
errors like this:

==3494== Memcheck, a memory error detector
==3494== Copyright © 2002-2011, and GNU GPL’d, by Julian Seward et al.
==3494== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==3494== Command: ./sdlbug
==3494==
==3494== Conditional jump or move depends on uninitialised value(s)
==3494== at 0x4066977: SDL_SendFingerDown (SDL_touch.c:353)
==3494== by 0x40D5C90: X11_PumpEvents (SDL_x11events.c:601)
==3494== by 0x4061063: SDL_PumpEvents (SDL_events.c:303)
==3494== by 0x4061599: SDL_WaitEventTimeout (SDL_events.c:336)
==3494== by 0x4061674: SDL_PollEvent (SDL_events.c:318)
==3494== by 0x804865D: main (sdlbug.c:14)
==3494== Uninitialised value was created by a stack allocation
==3494== at 0x40DA8B1: X11_InitTouch (SDL_x11touch.c:37)
==3494==
==3494==
==3494== HEAP SUMMARY:
==3494== in use at exit: 159,398 bytes in 937 blocks
==3494== total heap usage: 6,292 allocs, 5,355 frees, 3,726,924
bytes allocated
==3494==
==3494== 4 bytes in 1 blocks are definitely lost in loss record 12 of 508
==3494== at 0x4027984: operator new(unsigned int)
(vg_replace_malloc.c:282)
==3494== by 0x534B08E: ???
==3494== by 0x53327B1: ???
==3494== by 0x53479CA: ???
==3494== by 0x5347CB0: ???
==3494== by 0x5354ADF: ???
==3494== by 0x4A0EB50: ???
==3494== by 0x400EBE6: call_init (dl-init.c:70)
==3494== by 0x400ED08: _dl_init (dl-init.c:134)
==3494== by 0x4012E79: dl_open_worker (dl-open.c:478)
==3494== by 0x400E7F6: _dl_catch_error (dl-error.c:178)
==3494== by 0x40125A7: _dl_open (dl-open.c:569)
==3494==
==3494== 12 bytes in 1 blocks are definitely lost in loss record 30 of 508
==3494== at 0x4027984: operator new(unsigned int)
(vg_replace_malloc.c:282)
==3494== by 0x4DDB510: ???
==3494== by 0x53327B1: ???
==3494== by 0x4DD7BE3: ???
==3494== by 0x4DD7C6C: ???
==3494== by 0x4DD8484: ???
==3494== by 0x4E3B178: ???
==3494== by 0x4D0728E: ???
==3494== by 0x4CF41C7: ???
==3494== by 0x4EEE535: ???
==3494== by 0x4EEEC88: ???
==3494== by 0x4CD43E9: ???
==3494==
==3494== 14 bytes in 2 blocks are definitely lost in loss record 35 of 508
==3494== at 0x4026EE1: malloc (vg_replace_malloc.c:263)
==3494== by 0x47439CA: _XimEncodeString (in /usr/lib/libX11.so.6.3.0)
==3494== by 0x4742A14: _XimEncodeLocalICAttr (in
/usr/lib/libX11.so.6.3.0)
==3494== by 0x4743C25: _XimSetICValueData (in /usr/lib/libX11.so.6.3.0)
==3494== by 0x473EBBA: _XimLocalCreateIC (in /usr/lib/libX11.so.6.3.0)
==3494== by 0x4722F2B: XCreateIC (in /usr/lib/libX11.so.6.3.0)
==3494== by 0x40DC4DB: SetupWindowData (SDL_x11window.c:109)
==3494== by 0x40DCA09: X11_CreateWindow (SDL_x11window.c:552)
==3494== by 0x40C0A96: SDL_CreateWindow (SDL_video.c:1199)
==3494== by 0x40C0F6F: SDL_VideoInit (SDL_video.c:174)
==3494== by 0x4037FFB: SDL_InitSubSystem (SDL.c:74)
==3494== by 0x4038064: SDL_Init (SDL.c:150)
==3494==
==3494== 14 bytes in 2 blocks are definitely lost in loss record 36 of 508
==3494== at 0x4026EE1: malloc (vg_replace_malloc.c:263)
==3494== by 0x47439CA: _XimEncodeString (in /usr/lib/libX11.so.6.3.0)
==3494== by 0x4742A14: _XimEncodeLocalICAttr (in
/usr/lib/libX11.so.6.3.0)
==3494== by 0x4743C25: _XimSetICValueData (in /usr/lib/libX11.so.6.3.0)
==3494== by 0x473EBBA: _XimLocalCreateIC (in /usr/lib/libX11.so.6.3.0)
==3494== by 0x4722F2B: XCreateIC (in /usr/lib/libX11.so.6.3.0)
==3494== by 0x40DC4DB: SetupWindowData (SDL_x11window.c:109)
==3494== by 0x40DCA09: X11_CreateWindow (SDL_x11window.c:552)
==3494== by 0x40C0A96: SDL_CreateWindow (SDL_video.c:1199)
==3494== by 0x8048620: main (sdlbug.c:7)
==3494==
==3494== 20 (12 direct, 8 indirect) bytes in 1 blocks are definitely
lost in loss record 138 of 508
==3494== at 0x4027984: operator new(unsigned int)
(vg_replace_malloc.c:282)
==3494== by 0x532D933: ???
==3494== by 0x4CE9530: ???
==3494== by 0x4CF3905: ???
==3494== by 0x4CF3AD2: ???
==3494== by 0x4CA1287: ???
==3494== by 0x4CA1322: ???
==3494== by 0x4A53868: ???
==3494== by 0x4A6B718: ???
==3494== by 0x4A14459: ???
==3494== by 0x4A10BA2: ???
==3494== by 0x4A10C03: ???
==3494==
==3494== 36 (12 direct, 24 indirect) bytes in 1 blocks are definitely
lost in loss record 298 of 508
==3494== at 0x4027984: operator new(unsigned int)
(vg_replace_malloc.c:282)
==3494== by 0x4DFE523: ???
==3494== by 0x53327B1: ???
==3494== by 0x5344651: ???
==3494== by 0x4CE19AA: ???
==3494== by 0x4CE1AE5: ???
==3494== by 0x4CDC7D9: ???
==3494== by 0x4CD427E: ???
==3494== by 0x4CD4559: ???
==3494== by 0x4CE95BE: ???
==3494== by 0x4CF3905: ???
==3494== by 0x4CF3AD2: ???
==3494==
==3494== 36 (12 direct, 24 indirect) bytes in 1 blocks are definitely
lost in loss record 299 of 508
==3494== at 0x4027984: operator new(unsigned int)
(vg_replace_malloc.c:282)
==3494== by 0x4DFE523: ???
==3494== by 0x53327B1: ???
==3494== by 0x5298BEA: ???
==3494== by 0x528B036: ???
==3494== by 0x528D6E7: ???
==3494== by 0x5354ADF: ???
==3494== by 0x4A0EB50: ???
==3494== by 0x400EBE6: call_init (dl-init.c:70)
==3494== by 0x400ED08: _dl_init (dl-init.c:134)
==3494== by 0x4012E79: dl_open_worker (dl-open.c:478)
==3494== by 0x400E7F6: _dl_catch_error (dl-error.c:178)
==3494==
==3494== 64 (40 direct, 24 indirect) bytes in 1 blocks are definitely
lost in loss record 321 of 508
==3494== at 0x4027984: operator new(unsigned int)
(vg_replace_malloc.c:282)
==3494== by 0x4CD2816: ???
==3494== by 0x53327B1: ???
==3494== by 0x4CD444E: ???
==3494== by 0x4CD4559: ???
==3494== by 0x4CE95BE: ???
==3494== by 0x4CF3905: ???
==3494== by 0x4CF3AD2: ???
==3494== by 0x4CA1287: ???
==3494== by 0x4CA1322: ???
==3494== by 0x4A53868: ???
==3494== by 0x4A6B718: ???
==3494==
==3494== 112 bytes in 1 blocks are definitely lost in loss record 351 of
508
==3494== at 0x4025BE5: calloc (vg_replace_malloc.c:566)
==3494== by 0x48A79D8: driswCreateScreen (drisw_glx.c:626)
==3494== by 0x488543E: __glXInitialize (glxext.c:784)
==3494== by 0x4881D6A: GetGLXPrivScreenConfig (glxcmds.c:176)
==3494== by 0x4883056: glXChooseVisual (glxcmds.c:1234)
==3494== by 0x40D9D04: X11_GL_InitExtensions (SDL_x11opengl.c:434)
==3494== by 0x40DA3D6: X11_GL_LoadLibrary (SDL_x11opengl.c:186)
==3494== by 0x40BDFEF: SDL_GL_LoadLibrary (SDL_video.c:2135)
==3494== by 0x40C09C9: SDL_CreateWindow (SDL_video.c:1167)
==3494== by 0x40C0F6F: SDL_VideoInit (SDL_video.c:174)
==3494== by 0x4037FFB: SDL_InitSubSystem (SDL.c:74)
==3494== by 0x4038064: SDL_Init (SDL.c:150)
==3494==
==3494== 190 (100 direct, 90 indirect) bytes in 1 blocks are
definitely lost in loss record 374 of 508
==3494== at 0x4026EE1: malloc (vg_replace_malloc.c:263)
==3494== by 0x4065EC2: SDL_AddTouch (SDL_touch.c:120)
==3494== by 0x40DABD4: X11_InitTouch (SDL_x11touch.c:90)
==3494== by 0x40DB4CF: X11_VideoInit (SDL_x11video.c:367)
==3494== by 0x40C0E66: SDL_VideoInit (SDL_video.c:507)
==3494== by 0x4037FFB: SDL_InitSubSystem (SDL.c:74)
==3494== by 0x4038064: SDL_Init (SDL.c:150)
==3494== by 0x80485EC: main (sdlbug.c:6)
==3494==
==3494== 8,439 (4 direct, 8,435 indirect) bytes in 1 blocks are
definitely lost in loss record 505 of 508
==3494== at 0x4027984: operator new(unsigned int)
(vg_replace_malloc.c:282)
==3494== by 0x5298E5E: ???
==3494== by 0x53327B1: ???
==3494== by 0x52973CA: ???
==3494== by 0x528B02A: ???
==3494== by 0x528D6E7: ???
==3494== by 0x5354ADF: ???
==3494== by 0x4A0EB50: ???
==3494== by 0x400EBE6: call_init (dl-init.c:70)
==3494== by 0x400ED08: _dl_init (dl-init.c:134)
==3494== by 0x4012E79: dl_open_worker (dl-open.c:478)
==3494== by 0x400E7F6: _dl_catch_error (dl-error.c:178)
==3494==
==3494== 109,189 (28 direct, 109,161 indirect) bytes in 1 blocks are
definitely lost in loss record 508 of 508
==3494== at 0x4025BE5: calloc (vg_replace_malloc.c:566)
==3494== by 0x4CA1313: ???
==3494== by 0x4A53868: ???
==3494== by 0x4A6B718: ???
==3494== by 0x4A14459: ???
==3494== by 0x4A10BA2: ???
==3494== by 0x4A10C03: ???
==3494== by 0x4A10C3D: ???
==3494== by 0x48A797B: drisw_create_context (drisw_glx.c:404)
==3494== by 0x4882552: CreateContext (glxcmds.c:276)
==3494== by 0x48837D1: glXCreateContext (glxcmds.c:381)
==3494== by 0x40D9DF5: X11_GL_InitExtensions (SDL_x11opengl.c:278)
==3494==
==3494== LEAK SUMMARY:
==3494== definitely lost: 364 bytes in 14 blocks
==3494== indirectly lost: 117,766 bytes in 456 blocks
==3494== possibly lost: 0 bytes in 0 blocks
==3494== still reachable: 41,268 bytes in 467 blocks
==3494== suppressed: 0 bytes in 0 blocks
==3494== Reachable blocks (those to which a pointer was found) are not
shown.
==3494== To see them, rerun with: --leak-check=full --show-reachable=yes
==3494==
==3494== For counts of detected and suppressed errors, rerun with: -v
==3494== ERROR SUMMARY: 13 errors from 13 contexts (suppressed: 194 from
13)

Check the attachment for the lame code sdlbug.c (without checking
return value of SDL_Init).

Thanks.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Thanks.
Yes, uninitialised message of Valgrind goes away if
SDL_touchPads[index]->x_min = SDL_touchPads[index]->y_min = 0 was
inserted to line 145 of SDL_touch.c.

Here is the new output of Valgrind:

==4656== Memcheck, a memory error detector
==4656== Copyright © 2002-2011, and GNU GPL’d, by Julian Seward et al.
==4656== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==4656== Command: ./sdlbug
==4656==
==4656==
==4656== HEAP SUMMARY:
==4656== in use at exit: 159,398 bytes in 937 blocks
==4656== total heap usage: 6,386 allocs, 5,449 frees, 3,728,992
bytes allocated
==4656==
==4656== 4 bytes in 1 blocks are definitely lost in loss record 12 of 508
==4656== at 0x4027984: operator new(unsigned int) (vg_replace_malloc.c:282)
==4656== by 0x534B08E: ???
==4656== by 0x53327B1: ???
==4656== by 0x53479CA: ???
==4656== by 0x5347CB0: ???
==4656== by 0x5354ADF: ???
==4656== by 0x4A0EB50: ???
==4656== by 0x400EBE6: call_init (dl-init.c:70)
==4656== by 0x400ED08: _dl_init (dl-init.c:134)
==4656== by 0x4012E79: dl_open_worker (dl-open.c:478)
==4656== by 0x400E7F6: _dl_catch_error (dl-error.c:178)
==4656== by 0x40125A7: _dl_open (dl-open.c:569)
==4656==
==4656== 12 bytes in 1 blocks are definitely lost in loss record 30 of 508
==4656== at 0x4027984: operator new(unsigned int) (vg_replace_malloc.c:282)
==4656== by 0x4DDB510: ???
==4656== by 0x53327B1: ???
==4656== by 0x4DD7BE3: ???
==4656== by 0x4DD7C6C: ???
==4656== by 0x4DD8484: ???
==4656== by 0x4E3B178: ???
==4656== by 0x4D0728E: ???
==4656== by 0x4CF41C7: ???
==4656== by 0x4EEE535: ???
==4656== by 0x4EEEC88: ???
==4656== by 0x4CD43E9: ???
==4656==
==4656== 14 bytes in 2 blocks are definitely lost in loss record 35 of 508
==4656== at 0x4026EE1: malloc (vg_replace_malloc.c:263)
==4656== by 0x47439CA: _XimEncodeString (in /usr/lib/libX11.so.6.3.0)
==4656== by 0x4742A14: _XimEncodeLocalICAttr (in /usr/lib/libX11.so.6.3.0)
==4656== by 0x4743C25: _XimSetICValueData (in /usr/lib/libX11.so.6.3.0)
==4656== by 0x473EBBA: _XimLocalCreateIC (in /usr/lib/libX11.so.6.3.0)
==4656== by 0x4722F2B: XCreateIC (in /usr/lib/libX11.so.6.3.0)
==4656== by 0x40DC4EB: SetupWindowData (SDL_x11window.c:109)
==4656== by 0x40DCA19: X11_CreateWindow (SDL_x11window.c:552)
==4656== by 0x40C0AA6: SDL_CreateWindow (SDL_video.c:1199)
==4656== by 0x40C0F7F: SDL_VideoInit (SDL_video.c:174)
==4656== by 0x4037FFB: SDL_InitSubSystem (SDL.c:74)
==4656== by 0x4038064: SDL_Init (SDL.c:150)
==4656==
==4656== 14 bytes in 2 blocks are definitely lost in loss record 36 of 508
==4656== at 0x4026EE1: malloc (vg_replace_malloc.c:263)
==4656== by 0x47439CA: _XimEncodeString (in /usr/lib/libX11.so.6.3.0)
==4656== by 0x4742A14: _XimEncodeLocalICAttr (in /usr/lib/libX11.so.6.3.0)
==4656== by 0x4743C25: _XimSetICValueData (in /usr/lib/libX11.so.6.3.0)
==4656== by 0x473EBBA: _XimLocalCreateIC (in /usr/lib/libX11.so.6.3.0)
==4656== by 0x4722F2B: XCreateIC (in /usr/lib/libX11.so.6.3.0)
==4656== by 0x40DC4EB: SetupWindowData (SDL_x11window.c:109)
==4656== by 0x40DCA19: X11_CreateWindow (SDL_x11window.c:552)
==4656== by 0x40C0AA6: SDL_CreateWindow (SDL_video.c:1199)
==4656== by 0x8048620: main (sdlbug.c:7)
==4656==
==4656== 20 (12 direct, 8 indirect) bytes in 1 blocks are definitely
lost in loss record 138 of 508
==4656== at 0x4027984: operator new(unsigned int) (vg_replace_malloc.c:282)
==4656== by 0x532D933: ???
==4656== by 0x4CE9530: ???
==4656== by 0x4CF3905: ???
==4656== by 0x4CF3AD2: ???
==4656== by 0x4CA1287: ???
==4656== by 0x4CA1322: ???
==4656== by 0x4A53868: ???
==4656== by 0x4A6B718: ???
==4656== by 0x4A14459: ???
==4656== by 0x4A10BA2: ???
==4656== by 0x4A10C03: ???
==4656==
==4656== 36 (12 direct, 24 indirect) bytes in 1 blocks are definitely
lost in loss record 298 of 508
==4656== at 0x4027984: operator new(unsigned int) (vg_replace_malloc.c:282)
==4656== by 0x4DFE523: ???
==4656== by 0x53327B1: ???
==4656== by 0x5344651: ???
==4656== by 0x4CE19AA: ???
==4656== by 0x4CE1AE5: ???
==4656== by 0x4CDC7D9: ???
==4656== by 0x4CD427E: ???
==4656== by 0x4CD4559: ???
==4656== by 0x4CE95BE: ???
==4656== by 0x4CF3905: ???
==4656== by 0x4CF3AD2: ???
==4656==
==4656== 36 (12 direct, 24 indirect) bytes in 1 blocks are definitely
lost in loss record 299 of 508
==4656== at 0x4027984: operator new(unsigned int) (vg_replace_malloc.c:282)
==4656== by 0x4DFE523: ???
==4656== by 0x53327B1: ???
==4656== by 0x5298BEA: ???
==4656== by 0x528B036: ???
==4656== by 0x528D6E7: ???
==4656== by 0x5354ADF: ???
==4656== by 0x4A0EB50: ???
==4656== by 0x400EBE6: call_init (dl-init.c:70)
==4656== by 0x400ED08: _dl_init (dl-init.c:134)
==4656== by 0x4012E79: dl_open_worker (dl-open.c:478)
==4656== by 0x400E7F6: _dl_catch_error (dl-error.c:178)
==4656==
==4656== 64 (40 direct, 24 indirect) bytes in 1 blocks are definitely
lost in loss record 321 of 508
==4656== at 0x4027984: operator new(unsigned int) (vg_replace_malloc.c:282)
==4656== by 0x4CD2816: ???
==4656== by 0x53327B1: ???
==4656== by 0x4CD444E: ???
==4656== by 0x4CD4559: ???
==4656== by 0x4CE95BE: ???
==4656== by 0x4CF3905: ???
==4656== by 0x4CF3AD2: ???
==4656== by 0x4CA1287: ???
==4656== by 0x4CA1322: ???
==4656== by 0x4A53868: ???
==4656== by 0x4A6B718: ???
==4656==
==4656== 112 bytes in 1 blocks are definitely lost in loss record 351 of 508
==4656== at 0x4025BE5: calloc (vg_replace_malloc.c:566)
==4656== by 0x48A79D8: driswCreateScreen (drisw_glx.c:626)
==4656== by 0x488543E: __glXInitialize (glxext.c:784)
==4656== by 0x4881D6A: GetGLXPrivScreenConfig (glxcmds.c:176)
==4656== by 0x4883056: glXChooseVisual (glxcmds.c:1234)
==4656== by 0x40D9D14: X11_GL_InitExtensions (SDL_x11opengl.c:434)
==4656== by 0x40DA3E6: X11_GL_LoadLibrary (SDL_x11opengl.c:186)
==4656== by 0x40BDFFF: SDL_GL_LoadLibrary (SDL_video.c:2135)
==4656== by 0x40C09D9: SDL_CreateWindow (SDL_video.c:1167)
==4656== by 0x40C0F7F: SDL_VideoInit (SDL_video.c:174)
==4656== by 0x4037FFB: SDL_InitSubSystem (SDL.c:74)
==4656== by 0x4038064: SDL_Init (SDL.c:150)
==4656==
==4656== 190 (100 direct, 90 indirect) bytes in 1 blocks are
definitely lost in loss record 374 of 508
==4656== at 0x4026EE1: malloc (vg_replace_malloc.c:263)
==4656== by 0x4065EC2: SDL_AddTouch (SDL_touch.c:120)
==4656== by 0x40DABE4: X11_InitTouch (SDL_x11touch.c:90)
==4656== by 0x40DB4DF: X11_VideoInit (SDL_x11video.c:367)
==4656== by 0x40C0E76: SDL_VideoInit (SDL_video.c:507)
==4656== by 0x4037FFB: SDL_InitSubSystem (SDL.c:74)
==4656== by 0x4038064: SDL_Init (SDL.c:150)
==4656== by 0x80485EC: main (sdlbug.c:6)
==4656==
==4656== 8,439 (4 direct, 8,435 indirect) bytes in 1 blocks are
definitely lost in loss record 505 of 508
==4656== at 0x4027984: operator new(unsigned int) (vg_replace_malloc.c:282)
==4656== by 0x5298E5E: ???
==4656== by 0x53327B1: ???
==4656== by 0x52973CA: ???
==4656== by 0x528B02A: ???
==4656== by 0x528D6E7: ???
==4656== by 0x5354ADF: ???
==4656== by 0x4A0EB50: ???
==4656== by 0x400EBE6: call_init (dl-init.c:70)
==4656== by 0x400ED08: _dl_init (dl-init.c:134)
==4656== by 0x4012E79: dl_open_worker (dl-open.c:478)
==4656== by 0x400E7F6: _dl_catch_error (dl-error.c:178)
==4656==
==4656== 109,189 (28 direct, 109,161 indirect) bytes in 1 blocks are
definitely lost in loss record 508 of 508
==4656== at 0x4025BE5: calloc (vg_replace_malloc.c:566)
==4656== by 0x4CA1313: ???
==4656== by 0x4A53868: ???
==4656== by 0x4A6B718: ???
==4656== by 0x4A14459: ???
==4656== by 0x4A10BA2: ???
==4656== by 0x4A10C03: ???
==4656== by 0x4A10C3D: ???
==4656== by 0x48A797B: drisw_create_context (drisw_glx.c:404)
==4656== by 0x4882552: CreateContext (glxcmds.c:276)
==4656== by 0x48837D1: glXCreateContext (glxcmds.c:381)
==4656== by 0x40D9E05: X11_GL_InitExtensions (SDL_x11opengl.c:278)
==4656==
==4656== LEAK SUMMARY:
==4656== definitely lost: 364 bytes in 14 blocks
==4656== indirectly lost: 117,766 bytes in 456 blocks
==4656== possibly lost: 0 bytes in 0 blocks
==4656== still reachable: 41,268 bytes in 467 blocks
==4656== suppressed: 0 bytes in 0 blocks
==4656== Reachable blocks (those to which a pointer was found) are not shown.
==4656== To see them, rerun with: --leak-check=full --show-reachable=yes
==4656==
==4656== For counts of detected and suppressed errors, rerun with: -v
==4656== ERROR SUMMARY: 12 errors from 12 contexts (suppressed: 194 from 13)On Fri, Mar 16, 2012 at 10:08 PM, Patrick Baggett <baggett.patrick at gmail.com> wrote:

http://hg.libsdl.org/SDL/file/6bb657898f55/src/events/SDL_touch.c

Line 130-146 seems initialize the SDL_Touch structure’s various fields.

130 SDL_touchPads[index]->focus = 0;

131 SDL_touchPads[index]->name = SDL_malloc((length + 2) *
sizeof(char));

132 SDL_strlcpy(SDL_touchPads[index]->name, name, length + 1);

133

134 SDL_touchPads[index]->num_fingers = 0;

135 SDL_touchPads[index]->max_fingers = 1;

136 SDL_touchPads[index]->fingers = (SDL_Finger *)
SDL_malloc(sizeof(SDL_Finger
));

137 SDL_touchPads[index]->fingers[0] = NULL;

138 SDL_touchPads[index]->buttonstate = 0;

139 SDL_touchPads[index]->relative_mode = SDL_FALSE;

140 SDL_touchPads[index]->flush_motion = SDL_FALSE;

141

142 SDL_touchPads[index]->xres = (1<<(16-1));

143 SDL_touchPads[index]->yres = (1<<(16-1));

144 SDL_touchPads[index]->pressureres = (1<<(16-1));

then Line 353 (valgrind)

if(xin < touch->x_min || yin < touch->y_min) return 0; //should defer if
only a partial input

I don’t see where touch->x_min and touch->y_min get initialized, so you may
have a legitimate bug here. The easiest way to tell (if you’re compiling
from source) is to modify SDL_touch.c around line 145 and add something like
SDL_touchPads[index]->x_min = SDL_touchPads[index]->y_min = 0; and see if
the Valgrind message goes away. That isn’t to say that is a proper fix by
any means – but it would definitely tell if those fields were uninitialized
and used.

On Fri, Mar 16, 2012 at 8:54 AM, Spark Around <@Spark_Around> wrote:

Valgrind always report "Conditional jump or move depends on
uninitialised value(s) " when I press some key to exit the event loop
for application based on SDL2.

Is valgrind wrong? Or is there problem in SDL?

The attachment is an lame example named sdlbug.c (without checking the
return value of SDL_Init).
Link sdlbug.c with SDL2 rev 6303 on 32bits gentoo linux. Run the
application with valgrind:

valgrind --leak-check=full --track-origins=yes ./sdlbug

When I press ESCAPE, the application terminates and valgrind print
errors like this:

==3494== Memcheck, a memory error detector
==3494== Copyright © 2002-2011, and GNU GPL’d, by Julian Seward et al.
==3494== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==3494== Command: ./sdlbug
==3494==
==3494== Conditional jump or move depends on uninitialised value(s)
==3494== ? ?at 0x4066977: SDL_SendFingerDown (SDL_touch.c:353)
==3494== ? ?by 0x40D5C90: X11_PumpEvents (SDL_x11events.c:601)
==3494== ? ?by 0x4061063: SDL_PumpEvents (SDL_events.c:303)
==3494== ? ?by 0x4061599: SDL_WaitEventTimeout (SDL_events.c:336)
==3494== ? ?by 0x4061674: SDL_PollEvent (SDL_events.c:318)
==3494== ? ?by 0x804865D: main (sdlbug.c:14)
==3494== ?Uninitialised value was created by a stack allocation
==3494== ? ?at 0x40DA8B1: X11_InitTouch (SDL_x11touch.c:37)
==3494==
==3494==
==3494== HEAP SUMMARY:
==3494== ? ? in use at exit: 159,398 bytes in 937 blocks
==3494== ? total heap usage: 6,292 allocs, 5,355 frees, 3,726,924
bytes allocated
==3494==
==3494== 4 bytes in 1 blocks are definitely lost in loss record 12 of 508
==3494== ? ?at 0x4027984: operator new(unsigned int)
(vg_replace_malloc.c:282)
==3494== ? ?by 0x534B08E: ???
==3494== ? ?by 0x53327B1: ???
==3494== ? ?by 0x53479CA: ???
==3494== ? ?by 0x5347CB0: ???
==3494== ? ?by 0x5354ADF: ???
==3494== ? ?by 0x4A0EB50: ???
==3494== ? ?by 0x400EBE6: call_init (dl-init.c:70)
==3494== ? ?by 0x400ED08: _dl_init (dl-init.c:134)
==3494== ? ?by 0x4012E79: dl_open_worker (dl-open.c:478)
==3494== ? ?by 0x400E7F6: _dl_catch_error (dl-error.c:178)
==3494== ? ?by 0x40125A7: _dl_open (dl-open.c:569)
==3494==
==3494== 12 bytes in 1 blocks are definitely lost in loss record 30 of 508
==3494== ? ?at 0x4027984: operator new(unsigned int)
(vg_replace_malloc.c:282)
==3494== ? ?by 0x4DDB510: ???
==3494== ? ?by 0x53327B1: ???
==3494== ? ?by 0x4DD7BE3: ???
==3494== ? ?by 0x4DD7C6C: ???
==3494== ? ?by 0x4DD8484: ???
==3494== ? ?by 0x4E3B178: ???
==3494== ? ?by 0x4D0728E: ???
==3494== ? ?by 0x4CF41C7: ???
==3494== ? ?by 0x4EEE535: ???
==3494== ? ?by 0x4EEEC88: ???
==3494== ? ?by 0x4CD43E9: ???
==3494==
==3494== 14 bytes in 2 blocks are definitely lost in loss record 35 of 508
==3494== ? ?at 0x4026EE1: malloc (vg_replace_malloc.c:263)
==3494== ? ?by 0x47439CA: _XimEncodeString (in /usr/lib/libX11.so.6.3.0)
==3494== ? ?by 0x4742A14: _XimEncodeLocalICAttr (in
/usr/lib/libX11.so.6.3.0)
==3494== ? ?by 0x4743C25: _XimSetICValueData (in /usr/lib/libX11.so.6.3.0)
==3494== ? ?by 0x473EBBA: _XimLocalCreateIC (in /usr/lib/libX11.so.6.3.0)
==3494== ? ?by 0x4722F2B: XCreateIC (in /usr/lib/libX11.so.6.3.0)
==3494== ? ?by 0x40DC4DB: SetupWindowData (SDL_x11window.c:109)
==3494== ? ?by 0x40DCA09: X11_CreateWindow (SDL_x11window.c:552)
==3494== ? ?by 0x40C0A96: SDL_CreateWindow (SDL_video.c:1199)
==3494== ? ?by 0x40C0F6F: SDL_VideoInit (SDL_video.c:174)
==3494== ? ?by 0x4037FFB: SDL_InitSubSystem (SDL.c:74)
==3494== ? ?by 0x4038064: SDL_Init (SDL.c:150)
==3494==
==3494== 14 bytes in 2 blocks are definitely lost in loss record 36 of 508
==3494== ? ?at 0x4026EE1: malloc (vg_replace_malloc.c:263)
==3494== ? ?by 0x47439CA: _XimEncodeString (in /usr/lib/libX11.so.6.3.0)
==3494== ? ?by 0x4742A14: _XimEncodeLocalICAttr (in
/usr/lib/libX11.so.6.3.0)
==3494== ? ?by 0x4743C25: _XimSetICValueData (in /usr/lib/libX11.so.6.3.0)
==3494== ? ?by 0x473EBBA: _XimLocalCreateIC (in /usr/lib/libX11.so.6.3.0)
==3494== ? ?by 0x4722F2B: XCreateIC (in /usr/lib/libX11.so.6.3.0)
==3494== ? ?by 0x40DC4DB: SetupWindowData (SDL_x11window.c:109)
==3494== ? ?by 0x40DCA09: X11_CreateWindow (SDL_x11window.c:552)
==3494== ? ?by 0x40C0A96: SDL_CreateWindow (SDL_video.c:1199)
==3494== ? ?by 0x8048620: main (sdlbug.c:7)
==3494==
==3494== 20 (12 direct, 8 indirect) bytes in 1 blocks are definitely
lost in loss record 138 of 508
==3494== ? ?at 0x4027984: operator new(unsigned int)
(vg_replace_malloc.c:282)
==3494== ? ?by 0x532D933: ???
==3494== ? ?by 0x4CE9530: ???
==3494== ? ?by 0x4CF3905: ???
==3494== ? ?by 0x4CF3AD2: ???
==3494== ? ?by 0x4CA1287: ???
==3494== ? ?by 0x4CA1322: ???
==3494== ? ?by 0x4A53868: ???
==3494== ? ?by 0x4A6B718: ???
==3494== ? ?by 0x4A14459: ???
==3494== ? ?by 0x4A10BA2: ???
==3494== ? ?by 0x4A10C03: ???
==3494==
==3494== 36 (12 direct, 24 indirect) bytes in 1 blocks are definitely
lost in loss record 298 of 508
==3494== ? ?at 0x4027984: operator new(unsigned int)
(vg_replace_malloc.c:282)
==3494== ? ?by 0x4DFE523: ???
==3494== ? ?by 0x53327B1: ???
==3494== ? ?by 0x5344651: ???
==3494== ? ?by 0x4CE19AA: ???
==3494== ? ?by 0x4CE1AE5: ???
==3494== ? ?by 0x4CDC7D9: ???
==3494== ? ?by 0x4CD427E: ???
==3494== ? ?by 0x4CD4559: ???
==3494== ? ?by 0x4CE95BE: ???
==3494== ? ?by 0x4CF3905: ???
==3494== ? ?by 0x4CF3AD2: ???
==3494==
==3494== 36 (12 direct, 24 indirect) bytes in 1 blocks are definitely
lost in loss record 299 of 508
==3494== ? ?at 0x4027984: operator new(unsigned int)
(vg_replace_malloc.c:282)
==3494== ? ?by 0x4DFE523: ???
==3494== ? ?by 0x53327B1: ???
==3494== ? ?by 0x5298BEA: ???
==3494== ? ?by 0x528B036: ???
==3494== ? ?by 0x528D6E7: ???
==3494== ? ?by 0x5354ADF: ???
==3494== ? ?by 0x4A0EB50: ???
==3494== ? ?by 0x400EBE6: call_init (dl-init.c:70)
==3494== ? ?by 0x400ED08: _dl_init (dl-init.c:134)
==3494== ? ?by 0x4012E79: dl_open_worker (dl-open.c:478)
==3494== ? ?by 0x400E7F6: _dl_catch_error (dl-error.c:178)
==3494==
==3494== 64 (40 direct, 24 indirect) bytes in 1 blocks are definitely
lost in loss record 321 of 508
==3494== ? ?at 0x4027984: operator new(unsigned int)
(vg_replace_malloc.c:282)
==3494== ? ?by 0x4CD2816: ???
==3494== ? ?by 0x53327B1: ???
==3494== ? ?by 0x4CD444E: ???
==3494== ? ?by 0x4CD4559: ???
==3494== ? ?by 0x4CE95BE: ???
==3494== ? ?by 0x4CF3905: ???
==3494== ? ?by 0x4CF3AD2: ???
==3494== ? ?by 0x4CA1287: ???
==3494== ? ?by 0x4CA1322: ???
==3494== ? ?by 0x4A53868: ???
==3494== ? ?by 0x4A6B718: ???
==3494==
==3494== 112 bytes in 1 blocks are definitely lost in loss record 351 of
508
==3494== ? ?at 0x4025BE5: calloc (vg_replace_malloc.c:566)
==3494== ? ?by 0x48A79D8: driswCreateScreen (drisw_glx.c:626)
==3494== ? ?by 0x488543E: __glXInitialize (glxext.c:784)
==3494== ? ?by 0x4881D6A: GetGLXPrivScreenConfig (glxcmds.c:176)
==3494== ? ?by 0x4883056: glXChooseVisual (glxcmds.c:1234)
==3494== ? ?by 0x40D9D04: X11_GL_InitExtensions (SDL_x11opengl.c:434)
==3494== ? ?by 0x40DA3D6: X11_GL_LoadLibrary (SDL_x11opengl.c:186)
==3494== ? ?by 0x40BDFEF: SDL_GL_LoadLibrary (SDL_video.c:2135)
==3494== ? ?by 0x40C09C9: SDL_CreateWindow (SDL_video.c:1167)
==3494== ? ?by 0x40C0F6F: SDL_VideoInit (SDL_video.c:174)
==3494== ? ?by 0x4037FFB: SDL_InitSubSystem (SDL.c:74)
==3494== ? ?by 0x4038064: SDL_Init (SDL.c:150)
==3494==
==3494== 190 (100 direct, 90 indirect) bytes in 1 blocks are
definitely lost in loss record 374 of 508
==3494== ? ?at 0x4026EE1: malloc (vg_replace_malloc.c:263)
==3494== ? ?by 0x4065EC2: SDL_AddTouch (SDL_touch.c:120)
==3494== ? ?by 0x40DABD4: X11_InitTouch (SDL_x11touch.c:90)
==3494== ? ?by 0x40DB4CF: X11_VideoInit (SDL_x11video.c:367)
==3494== ? ?by 0x40C0E66: SDL_VideoInit (SDL_video.c:507)
==3494== ? ?by 0x4037FFB: SDL_InitSubSystem (SDL.c:74)
==3494== ? ?by 0x4038064: SDL_Init (SDL.c:150)
==3494== ? ?by 0x80485EC: main (sdlbug.c:6)
==3494==
==3494== 8,439 (4 direct, 8,435 indirect) bytes in 1 blocks are
definitely lost in loss record 505 of 508
==3494== ? ?at 0x4027984: operator new(unsigned int)
(vg_replace_malloc.c:282)
==3494== ? ?by 0x5298E5E: ???
==3494== ? ?by 0x53327B1: ???
==3494== ? ?by 0x52973CA: ???
==3494== ? ?by 0x528B02A: ???
==3494== ? ?by 0x528D6E7: ???
==3494== ? ?by 0x5354ADF: ???
==3494== ? ?by 0x4A0EB50: ???
==3494== ? ?by 0x400EBE6: call_init (dl-init.c:70)
==3494== ? ?by 0x400ED08: _dl_init (dl-init.c:134)
==3494== ? ?by 0x4012E79: dl_open_worker (dl-open.c:478)
==3494== ? ?by 0x400E7F6: _dl_catch_error (dl-error.c:178)
==3494==
==3494== 109,189 (28 direct, 109,161 indirect) bytes in 1 blocks are
definitely lost in loss record 508 of 508
==3494== ? ?at 0x4025BE5: calloc (vg_replace_malloc.c:566)
==3494== ? ?by 0x4CA1313: ???
==3494== ? ?by 0x4A53868: ???
==3494== ? ?by 0x4A6B718: ???
==3494== ? ?by 0x4A14459: ???
==3494== ? ?by 0x4A10BA2: ???
==3494== ? ?by 0x4A10C03: ???
==3494== ? ?by 0x4A10C3D: ???
==3494== ? ?by 0x48A797B: drisw_create_context (drisw_glx.c:404)
==3494== ? ?by 0x4882552: CreateContext (glxcmds.c:276)
==3494== ? ?by 0x48837D1: glXCreateContext (glxcmds.c:381)
==3494== ? ?by 0x40D9DF5: X11_GL_InitExtensions (SDL_x11opengl.c:278)
==3494==
==3494== LEAK SUMMARY:
==3494== ? ?definitely lost: 364 bytes in 14 blocks
==3494== ? ?indirectly lost: 117,766 bytes in 456 blocks
==3494== ? ? ?possibly lost: 0 bytes in 0 blocks
==3494== ? ?still reachable: 41,268 bytes in 467 blocks
==3494== ? ? ? ? suppressed: 0 bytes in 0 blocks
==3494== Reachable blocks (those to which a pointer was found) are not
shown.
==3494== To see them, rerun with: --leak-check=full --show-reachable=yes
==3494==
==3494== For counts of detected and suppressed errors, rerun with: -v
==3494== ERROR SUMMARY: 13 errors from 13 contexts (suppressed: 194 from
13)

Check the attachment for the lame code sdlbug.c (without checking
return value of SDL_Init).

Thanks.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Interesting. Sam was the last one who worked on this. Can you comment or
otherwise review how these members are used?

As I mentioned before, just setting those to zero was just a check to see
if that was the issue. I’m not familiar with the touch code and I have no
idea what the actual fix is.

Patrick> On Fri, Mar 16, 2012 at 10:08 PM, Patrick Baggett <@Patrick_Baggett> wrote:

http://hg.libsdl.org/SDL/file/6bb657898f55/src/events/SDL_touch.c

Line 130-146 seems initialize the SDL_Touch structure’s various fields.

130 SDL_touchPads[index]->focus = 0;

131 SDL_touchPads[index]->name = SDL_malloc((length + 2) *
sizeof(char));

132 SDL_strlcpy(SDL_touchPads[index]->name, name, length + 1);

133

134 SDL_touchPads[index]->num_fingers = 0;

135 SDL_touchPads[index]->max_fingers = 1;

136 SDL_touchPads[index]->fingers = (SDL_Finger *)
SDL_malloc(sizeof(SDL_Finger
));

137 SDL_touchPads[index]->fingers[0] = NULL;

138 SDL_touchPads[index]->buttonstate = 0;

139 SDL_touchPads[index]->relative_mode = SDL_FALSE;

140 SDL_touchPads[index]->flush_motion = SDL_FALSE;

141

142 SDL_touchPads[index]->xres = (1<<(16-1));

143 SDL_touchPads[index]->yres = (1<<(16-1));

144 SDL_touchPads[index]->pressureres = (1<<(16-1));

then Line 353 (valgrind)

if(xin < touch->x_min || yin < touch->y_min) return 0; //should defer if
only a partial input

I don’t see where touch->x_min and touch->y_min get initialized, so you
may
have a legitimate bug here. The easiest way to tell (if you’re compiling
from source) is to modify SDL_touch.c around line 145 and add something
like
SDL_touchPads[index]->x_min = SDL_touchPads[index]->y_min = 0; and see if
the Valgrind message goes away. That isn’t to say that is a proper fix by
any means – but it would definitely tell if those fields were
uninitialized
and used.

On Fri, Mar 16, 2012 at 8:54 AM, Spark Around wrote:

Valgrind always report "Conditional jump or move depends on
uninitialised value(s) " when I press some key to exit the event loop
for application based on SDL2.

Is valgrind wrong? Or is there problem in SDL?

I am also not familiar with the touch code. I reviewed the code
roughly and found that the problem was triggered by invalid ioctl
calls in
http://hg.libsdl.org/SDL/file/6bb657898f55/src/video/x11/SDL_x11touch.c:

76 int abs[5];
77 ioctl(data->eventStream,EVIOCGABS(0),abs);
78 touch.x_min = abs[1];
79 touch.x_max = abs[2];
80 touch.native_xres = touch.x_max - touch.x_min;
81 ioctl(data->eventStream,EVIOCGABS(ABS_Y),abs);
82 touch.y_min = abs[1];
83 touch.y_max = abs[2];
84 touch.native_yres = touch.y_max - touch.y_min;
85 ioctl(data->eventStream,EVIOCGABS(ABS_PRESSURE),abs);
86 touch.pressure_min = abs[1];
87 touch.pressure_max = abs[2];
88 touch.native_pressureres = touch.pressure_max - touch.pressure_min;
89
90 SDL_AddTouch(&touch, tstr);
The ioctl function at line 77,81,85 return -1 and the error message
(perror) is Invalid argument.
If touch.x_min = touch.y_min = 0 was inserted before line 90, the
uninitialised message of valgrind disappeared. So the uninitialised
abs due to invalid call of ioctl is the source of the uninitialised
values problem.

On the other hand, my keyboard maybe was recognized as “touchpad” .
cat /proc/bus/input/devices:

I: Bus=0011 Vendor=0001 Product=0001 Version=ab54
N: Name="AT Translated Set 2 keyboard"
P: Phys=isa0060/serio0/input0
S: Sysfs=/devices/platform/i8042/serio0/input/input3
U: Uniq=
H: Handlers=sysrq kbd event3
B: PROP=0
B: EV=120013
B: KEY=4 2000000 3803078 f800d001 feffffdf ffefffff ffffffff fffffffe
B: MSC=10
B: LED=7

The value of Vendor is 1. And the line 50 of SDL_x11touch.c:

47 while(!feof(fd)) {
48 if(fgets(line,256,fd) <=0) continue;
49 if(line[0] == ‘\n’) {
50 if(vendor == 1386 || vendor==1) {
51
52 sprintf(tstr,"/dev/input/event%i",event);
53
54 tsfd = open( tstr, O_RDONLY | O_NONBLOCK );
55 if ( tsfd == -1 )
56 continue; /* Maybe not enough permissions ? */
57
58 SDL_Touch touch;
59 touch.pressure_max = 0;

Can we make sure that a device is an touchpad if the value of the Vender is 1?
Is that the original source of this bug?On Fri, Mar 16, 2012 at 11:00 PM, Patrick Baggett <baggett.patrick at gmail.com> wrote:

Interesting. Sam was the last one who worked on this. Can you comment or
otherwise review how these members are used?

As I mentioned before, just setting those to zero was just a check to see if
that was the issue. I’m not familiar with the touch code and I have no idea
what the actual fix is.

Patrick

On Fri, Mar 16, 2012 at 10:08 PM, Patrick Baggett <baggett.patrick at gmail.com> wrote:

http://hg.libsdl.org/SDL/file/6bb657898f55/src/events/SDL_touch.c

Line 130-146 seems initialize the SDL_Touch structure’s various fields.

? ?130 ? ? SDL_touchPads[index]->focus = 0;

? ?131 ? ? SDL_touchPads[index]->name = SDL_malloc((length + 2) *
sizeof(char));

? ?132 ? ? SDL_strlcpy(SDL_touchPads[index]->name, name, length + 1);

? ?133

? ?134 ? ? SDL_touchPads[index]->num_fingers = 0;

? ?135 ? ? SDL_touchPads[index]->max_fingers = 1;

? ?136 ? ? SDL_touchPads[index]->fingers = (SDL_Finger *)
SDL_malloc(sizeof(SDL_Finger
));

? ?137 ? ? SDL_touchPads[index]->fingers[0] = NULL;

? ?138 ? ? SDL_touchPads[index]->buttonstate = 0;

? ?139 ? ? SDL_touchPads[index]->relative_mode = SDL_FALSE;

? ?140 ? ? SDL_touchPads[index]->flush_motion = SDL_FALSE;

? ?141

? ?142 ? ? SDL_touchPads[index]->xres = (1<<(16-1));

? ?143 ? ? SDL_touchPads[index]->yres = (1<<(16-1));

? ?144 ? ? SDL_touchPads[index]->pressureres = (1<<(16-1));

then Line 353 (valgrind)

if(xin < touch->x_min || yin < touch->y_min) return 0; //should defer if
only a partial input

I don’t see where touch->x_min and touch->y_min get initialized, so you
may
have a legitimate bug here. The easiest way to tell (if you’re compiling
from source) is to modify SDL_touch.c around line 145 and add something
like
SDL_touchPads[index]->x_min = SDL_touchPads[index]->y_min = 0; and see
if
the Valgrind message goes away. That isn’t to say that is a proper fix
by
any means – but it would definitely tell if those fields were
uninitialized
and used.

On Fri, Mar 16, 2012 at 8:54 AM, Spark Around <@Spark_Around> wrote:

Valgrind always report "Conditional jump or move depends on
uninitialised value(s) " when I press some key to exit the event loop
for application based on SDL2.

Is valgrind wrong? Or is there problem in SDL?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org