Could someone please correct me if I’m wrong, but I believe
I have found a bug in the SDL 1.2.8 source code:
File: "SDL-1.2.8/src/video/SDL_surface.c"
Line: 87
The pointer surface is never initialized, but is
dereferenced as a “size_t” argument of malloc.
/* Allocate the surface */
/* BUG BELOW THIS LINE??? */
surface = (SDL_Surface *)malloc(sizeof(surface));
/ BUG ABOVE THIS LINE??? */
if ( surface == NULL ) {
SDL_OutOfMemory();
return(NULL);
}
Thanks,
Paul Lowe
paul at tetravista.net
The pointer surface is never initialized, but is
dereferenced as a “size_t” argument of malloc.
/* Allocate the surface */
/* BUG BELOW THIS LINE??? */
surface = (SDL_Surface *)malloc(sizeof(surface));
/ BUG ABOVE THIS LINE??? */
Not a dereference in sizeof()…this is naughty C syntax stuff.
For a clearer example:
#include <stdio.h>
int main(void)
{
int *x = NULL;
printf("%d\n%d\n", sizeof (*x), sizeof (5+1));
return(0);
}
–ryan.
Could someone please correct me if I’m wrong, but I believe
I have found a bug in the SDL 1.2.8 source code:
[…]
surface = (SDL_Surface *)malloc(sizeof(*surface));
[…]
This just determines the size of the target type of the surface
pointer at compile time (C is a statically typed language! :-), so
the value of the pointer at run time is totally irrelevant.
//David Olofson - Programmer, Composer, Open Source Advocate
.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,… |
`-----------------------------------> http://audiality.org -’
— http://olofson.net — http://www.reologica.se —On Thursday 21 April 2005 08.44, Paul Lowe wrote: