SDL_FillRect modifiles the value of the SDL_Rect parameter

The following program will cause a segmentation fault:

#include <SDL.h>

SDL_Surface *screen;
Uint32 darkgray;
const SDL_Rect r={10,10,10,10};
int quit=0;

void init_SDL()
{
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr,
“Couldn’t initialize SDL: %s\n”,
SDL_GetError());
exit(1);
}
atexit(SDL_Quit);

/* Initialize the display */
screen = SDL_SetVideoMode(800, 600, 0,
SDL_SWSURFACE|SDL_ANYFORMAT);
if ( screen == NULL ) {
fprintf(stderr, “Couldn’t set video mode: %s\n”,
SDL_GetError());
exit(1);
}
}

int main(int argc, char *argv[])
{
init_SDL();

darkgray=SDL_MapRGB(screen->format,100,100,100);
SDL_FillRect(screen, &r, darkgray);
SDL_UpdateRect(screen, 0,0,0,0);
while (1) SDL_Delay(10);
}

Is this behavoir normal?
Why doesn’t the documentation warn about this?

Thanks

Alessandro.______________________________________________________________________
Yahoo! Mail: 6MB di spazio gratuito, 30MB per i tuoi allegati, l’antivirus, il filtro Anti-spam
http://it.yahoo.com/mail_it/foot/?http://it.mail.yahoo.com/

No, I dont think that SDL_FillRect modifiles the rect.
Is the const absolutely necessary?
Remove the const and it should work (my compiler even gives
a compile error when using your code).

Thomas> ----- Original Message -----

From: a_staltari@yahoo.it (Alessandro Staltari)
To:
Sent: Thursday, August 14, 2003 2:37 PM
Subject: [SDL] SDL_FillRect modifiles the value of the SDL_Rect parameter

The following program will cause a segmentation fault:

#include <SDL.h>

SDL_Surface *screen;
Uint32 darkgray;
const SDL_Rect r={10,10,10,10};
int quit=0;

void init_SDL()
{
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr,
“Couldn’t initialize SDL: %s\n”,
SDL_GetError());
exit(1);
}
atexit(SDL_Quit);

/* Initialize the display */
screen = SDL_SetVideoMode(800, 600, 0,
SDL_SWSURFACE|SDL_ANYFORMAT);
if ( screen == NULL ) {
fprintf(stderr, “Couldn’t set video mode: %s\n”,
SDL_GetError());
exit(1);
}
}

int main(int argc, char *argv[])
{
init_SDL();

darkgray=SDL_MapRGB(screen->format,100,100,100);
SDL_FillRect(screen, &r, darkgray);
SDL_UpdateRect(screen, 0,0,0,0);
while (1) SDL_Delay(10);
}

Is this behavoir normal?
Why doesn’t the documentation warn about this?

Thanks

Alessandro.


Yahoo! Mail: 6MB di spazio gratuito, 30MB per i tuoi allegati, l’antivirus, il filtro Anti-spam
http://it.yahoo.com/mail_it/foot/?http://it.mail.yahoo.com/


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

Thomas Eder:

No, I dont think that SDL_FillRect modifiles the
rect.

I think in some cases the rect may be changed.
To verify if it was really possible I wrote the
sample program to demonstrate SDL_FillRect really
modifies the value of the rect.

If you remove the const keyword from the source I
posted, you will find the value after SDL_FillRect
returns is unchanged, but in the application I’m
developing there are cases when it seems to change.
It may be a buffer overflow, but electric fence don’t
detect it.

Is the const absolutely necessary?
Remove the const and it should work (my compiler
even gives
a compile error when using your code).

It gives an error or just a warning?

Thanks.

Alessandro.______________________________________________________________________
Yahoo! Mail: 6MB di spazio gratuito, 30MB per i tuoi allegati, l’antivirus, il filtro Anti-spam
http://it.yahoo.com/mail_it/foot/?http://it.mail.yahoo.com/

Thomas Eder:

No, I dont think that SDL_FillRect modifiles the
rect.

I think in some cases the rect may be changed.
To verify if it was really possible I wrote the
sample program to demonstrate SDL_FillRect really
modifies the value of the rect.

If you remove the const keyword from the source I
posted, you will find the value after SDL_FillRect
returns is unchanged, but in the application I’m
developing there are cases when it seems to change.
It may be a buffer overflow, but electric fence don’t
detect it.

It’s changed when the fill rect is clipped because it intersects the edge
of the surface you are filling. Both blit and fill do this so that you can
pass the rectangles directly to update rects without requiring an additional
clipping step.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

MSVC6 gives a compile error for me with your sample,

Thomas> ----- Original Message -----

From: a_staltari@yahoo.it (Alessandro Staltari)
To:
Sent: Thursday, August 14, 2003 3:49 PM
Subject: Re: [SDL] SDL_FillRect modifiles the value of the SDL_Rect parameter

Thomas Eder:

No, I dont think that SDL_FillRect modifiles the
rect.

I think in some cases the rect may be changed.
To verify if it was really possible I wrote the
sample program to demonstrate SDL_FillRect really
modifies the value of the rect.

If you remove the const keyword from the source I
posted, you will find the value after SDL_FillRect
returns is unchanged, but in the application I’m
developing there are cases when it seems to change.
It may be a buffer overflow, but electric fence don’t
detect it.

Is the const absolutely necessary?
Remove the const and it should work (my compiler
even gives
a compile error when using your code).

It gives an error or just a warning?

Thanks.

Alessandro.


Yahoo! Mail: 6MB di spazio gratuito, 30MB per i tuoi allegati, l’antivirus, il filtro Anti-spam
http://it.yahoo.com/mail_it/foot/?http://it.mail.yahoo.com/


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