Segmentation Fault in SDL_x11modes.c

Hi,

I’m using 1.2.6, compiled from source, on Linux.

I have found a SEGV in set_best_resolution(), SDL_x11modes.c, line 139:

if ( (modes[i]->hdisplay != mode.hdisplay) ||
        (modes[i]->vdisplay != mode.vdisplay) ) {

The preceding for loop exits and leaves i=-1. I think the invalid assumption
is that nmodes>1, which in my case is false, so the break statement is never
reached.

I wonder if the same error condition could occur if every mode is too small
for the requested window size, in which case best_width=0 always and again
the loop will exit with i=-1.

In either case adding
if (i<=0) i=0;
just before the match: label will select the largest (or only) resolution.
This has (sort-of) fixed it here, although it now seems to be very confused
about Xinerama. Without Xinerama, it’s fine.

Cheers,

Dave–
Dave Turner
@Dave_Turner

I have found a SEGV in set_best_resolution(), SDL_x11modes.c, line 139:

if ( (modes[i]->hdisplay != mode.hdisplay) ||
        (modes[i]->vdisplay != mode.vdisplay) ) {

Adding a check for i<0 is part of it, I’m wondering if the for loop
should, in addition, run while i >= 0 instead of i > 0…haven’t had my
morning coffee yet, though. Anyone?

–ryan.

The loop does run while i>=0, at least in the source of the 1.2.6 release:

       for ( i = nmodes-1; i >= 0 ; i-- ) {
    if ( ! best_width ) {
                if ( (modes[i]->hdisplay >= width) &&
                     (modes[i]->vdisplay >= height) ) {
                    best_width = modes[i]->hdisplay;
                    best_height = modes[i]->vdisplay;
                }
            } else {
                if ( (modes[i]->hdisplay != best_width) ||
                     (modes[i]->vdisplay != best_height) ) {
                    i++;
                    break;
                }
            }
        }

I have now convinced myself that this bug will manifest itself in the
following two cases:

(i) if you ask for a fullscreen window which is either wider or taller than
any supported resolution.

(ii) if you ask for a fullscreen window and only have one resolution
configured.

Cheers,

DaveOn Thursday 11 Dec 2003 2:33 pm, Ryan C. Gordon wrote:

I have found a SEGV in set_best_resolution(), SDL_x11modes.c, line 139:

if ( (modes[i]->hdisplay != mode.hdisplay) ||
        (modes[i]->vdisplay != mode.vdisplay) ) {

Adding a check for i<0 is part of it, I’m wondering if the for loop
should, in addition, run while i >= 0 instead of i > 0…haven’t had my
morning coffee yet, though. Anyone?


Dave Turner
@Dave_Turner

I have found a SEGV in set_best_resolution(), SDL_x11modes.c, line 139:

if ( (modes[i]->hdisplay != mode.hdisplay) ||
        (modes[i]->vdisplay != mode.vdisplay) ) {

Adding a check for i<0 is part of it, I’m wondering if the for loop
should, in addition, run while i >= 0 instead of i > 0…haven’t had my
morning coffee yet, though. Anyone?

The loop does run while i>=0, at least in the source of the 1.2.6 release:

       for ( i = nmodes-1; i >= 0 ; i-- ) {

Which should be;

for ( i = nmodes-1; i > 0 ; i-- ) {

I have now convinced myself that this bug will manifest itself in the
following two cases:

(i) if you ask for a fullscreen window which is either wider or taller than
any supported resolution.

(ii) if you ask for a fullscreen window and only have one resolution
configured.

Spotted at the end of August for option two. This is already fixed in
CVS from my mistake while fixing X4.3 support. For some reason I’d
chucked in the equals while moving code about.On Thu, 2003-12-11 at 15:48, Dave Turner wrote:

On Thursday 11 Dec 2003 2:33 pm, Ryan C. Gordon wrote:


Alan.

“One must never be purposelessnessnesslessness.”
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20031211/272e0813/attachment.pgp

possibly a “make” not a “SDL” problem, but i cant get further here…
i guess its some stupid thing i cannot know being a newbie again,

any idea on which list i should ask things like that?----------------------------------------------------------------------

Make Output:

make -k clean all
rm: cannot remove test.exe': No such file or directory make: *** [clean] Error 1 rm main.o test.exe g++ -c -g main.cpp g++ -L/SDL -g -o -lmingw32 -lSDLmain -lSDL main.o main.o(.text+0x88): In functionZ8SDL_mainv’:
D:/Applications/Eclipse/workspace/SDL_Learn/main.cpp:9: undefined
reference to SDL_Init' main.o(.text+0x9b):D:/Applications/Eclipse/workspace/SDL_Learn/main.cpp:10: undefined reference toSDL_GetError’
main.o(.text+0xd1):D:/Applications/Eclipse/workspace/SDL_Learn/main.cpp:19:
undefined reference to SDL_Quit' D:/Applications/MSYS/mingw/bin/../lib/gcc-lib/mingw32/3.2.3/../../../libmingw32.a(main.o)(.text+0x97):main.c: undefined reference toWinMain at 16’
make: *** [test.exe] Error 1
make: Target `all’ not remade because of errors.


MakeFile:

all: test.exe

clean:
rm main.o test.exe

test.exe: main.o
g++ -L/SDL -g -o -lmingw32 -lSDLmain -lSDL main.o

main.o:
g++ -c -g main.cpp


File Locations:

MSYS: D:\Applications\Msys
MINGW: D:\Applications\Msys\mingw
SDL: D:\Applications\Msys\mingw\include & D:\Applications\Msys\mingw\lib
ENV_PATH: D:\Applications\Msys\bin & D:\Applications\Msys\mingw\bin
main.cpp: D:\Applications\Eclipse\workspace\SDL_Learn\main.cpp


Code (should be the code from the docs, but with changed include
from "SDL.h" to <SDL/SDL.h>:

#include <SDL/SDL.h>
#include <stdio.h>

int main() {

 printf("Initializing SDL.\n");

 /* Initialize defaults, Video and Audio */
 if((SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO)==-1)) {
     printf("Could not initialize SDL: %s.\n", SDL_GetError());
     // exit(-1);
 }

 printf("SDL initialized.\n");

 printf("Quiting SDL.\n");

 /* Shutdown all subsystems */
 SDL_Quit();

 printf("Quiting....\n");

 // exit(0);

}

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi!
Actually it looks like the typicall error if the sdl-lib is not found. on the
otherside you are linking to sdl. did you try compiling using sdl-conifg

  • –cflags --libs ?
    regards
    MatthiasAm Donnerstag, 11. Dezember 2003 21:15 schrieb Jonas Hartmann:

possibly a “make” not a “SDL” problem, but i cant get further here…
i guess its some stupid thing i cannot know being a newbie again,

any idea on which list i should ask things like that?


Make Output:

make -k clean all
rm: cannot remove test.exe': No such file or directory make: *** [clean] Error 1 rm main.o test.exe g++ -c -g main.cpp g++ -L/SDL -g -o -lmingw32 -lSDLmain -lSDL main.o main.o(.text+0x88): In functionZ8SDL_mainv’:
D:/Applications/Eclipse/workspace/SDL_Learn/main.cpp:9: undefined
reference to SDL_Init' main.o(.text+0x9b):D:/Applications/Eclipse/workspace/SDL_Learn/main.cpp:10: undefined reference toSDL_GetError’
main.o(.text+0xd1):D:/Applications/Eclipse/workspace/SDL_Learn/main.cpp:19:
undefined reference to SDL_Quit' D:/Applications/MSYS/mingw/bin/../lib/gcc-lib/mingw32/3.2.3/../../../libmin gw32.a(main.o)(.text+0x97):main.c: undefined reference toWinMain at 16’
make: *** [test.exe] Error 1
make: Target `all’ not remade because of errors.


MakeFile:

all: test.exe

clean:
rm main.o test.exe

test.exe: main.o
g++ -L/SDL -g -o -lmingw32 -lSDLmain -lSDL main.o

main.o:
g++ -c -g main.cpp


File Locations:

MSYS: D:\Applications\Msys
MINGW: D:\Applications\Msys\mingw
SDL: D:\Applications\Msys\mingw\include & D:\Applications\Msys\mingw\lib
ENV_PATH: D:\Applications\Msys\bin & D:\Applications\Msys\mingw\bin
main.cpp: D:\Applications\Eclipse\workspace\SDL_Learn\main.cpp


Code (should be the code from the docs, but with changed include
from “SDL.h” to <SDL/SDL.h>:

#include <SDL/SDL.h>
#include <stdio.h>

int main() {

 printf("Initializing SDL.\n");

 /* Initialize defaults, Video and Audio */
 if((SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO)==-1)) {
     printf("Could not initialize SDL: %s.\n", SDL_GetError());
     // exit(-1);
 }

 printf("SDL initialized.\n");

 printf("Quiting SDL.\n");

 /* Shutdown all subsystems */
 SDL_Quit();

 printf("Quiting....\n");

 // exit(0);

}


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Matthias Bach | GPG/PGP-Key-ID: 0xACA73EC9
www.marix-world.de | On Keyserver: www.keyserver.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/2NpclnJmS6ynPskRAkkMAJ0eW4rX1ISESnonMnb/nCDV+yar4gCeJ1RX
KO+AkTBNNy1otF4N63bYKCs=
=7K8z
-----END PGP SIGNATURE-----

No it’s not.

make -k clean all
rm: cannot remove `test.exe’: No such file or directory

rm -f test.exe

Code (should be the code from the docs, but with changed include
from “SDL.h” to <SDL/SDL.h>:

#include <SDL/SDL.h>
#include <stdio.h>

int main() {

  1. Use sdl-config to get the right command to pass to your compiler. Then
    "SDL.h" will work, and you may find it fixes your unresolved symbols.

  2. The prototype is int main(int argc, char *argv[])

See the Windows FAQ on http://www.libsdl.org/On Thursday 11 Dec 2003 8:15 pm, Jonas Hartmann wrote:

Subject: Re: [SDL] Segmentation Fault in SDL_x11modes.c


Dave Turner
@Dave_Turner

Right-ho - I looked too briefly at the mailing list archives. Ta.

DaveOn Thursday 11 Dec 2003 7:48 pm, Alan Swanson wrote:

On Thu, 2003-12-11 at 15:48, Dave Turner wrote:

       for ( i = nmodes-1; i >= 0 ; i-- ) {

Which should be;

for ( i = nmodes-1; i > 0 ; i-- ) {

Spotted at the end of August for option two. This is already fixed in
CVS from my mistake while fixing X4.3 support. For some reason I’d
chucked in the equals while moving code about.


Dave Turner
@Dave_Turner