[AD] fixes.. malloc()

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


/allegro417/src/allegro.c(line 393)

void allegro_message(AL_CONST char *msg, ...)
{
   char *buf = malloc(ALLEGRO_MESSAGE_SIZE);
   char *tmp = malloc(ALLEGRO_MESSAGE_SIZE);
   va_list ap;
   ASSERT(msg);


malloc()  should be checked to see if it built.

same for

blit.c line 69
blit.c line 331


------------------------------------

/allegro417/src/readbmp.c  line55

for (iter = bitmap_type_list; iter->next; iter = iter->next);
iter = iter->next = malloc(sizeof(struct BITMAP_TYPE_INFO));

shouldn't the for loop go to just iter, so it finds the NULL on the end of list.

-------------------------------------

/allegro417/src/readbmp.c  line 149

if (rgb_map != NULL)
  free(rgb_map);


check is redundant as free safely ignores NULL ptrs.
(on win32 the docs say it does), if if doesn't, then
the rest of allegro's free()'s  need to be checked, as there are
several without checks.


check is redundant: (for the following)

destroy_rle_sprite();

scene3d.c line 62   if (scene_edge) free(scene_edge);

----------------------------------------

allegro417/src/win/gdi/c line 161

static BITMAPINFO *get_bitmap_info(BITMAP *bitmap, PALETTE pal)
{
   BITMAPINFO *bi;
   int bpp, i;

   bi = (BITMAPINFO *) malloc(sizeof(BITMAPINFO) + sizeof(RGBQUAD) * 256);


malloc() success check required.

--------------------------------------------

/allegro417/src/win/gdi.c  line 347

   bi.biClrUsed = 256;
   bi.biCompression = BI_RGB;

   binfo = malloc(sizeof(BITMAPINFO) + sizeof(RGBQUAD) * 256);
   binfo->bmiHeader = bi;

   hdc = GetDC(NULL);


malloc()  success check needed.

-------------------------------------------------

/allegro417/src/win/wddraw.c  line 165


/* create our pseudo surface memory */
pseudo_surf_mem = malloc(2048 * BYTES_PER_PIXEL(color_depth));

the way its created looks a bit dodgy, and then it
gets used elsewhere without much of a sanity check

---------------------------------------------------

/allegro417/src/win/wdsinput.c  line 220

test_wfx = malloc(sizeof(WAVEFORMATEX));

malloc() success check reqd.

----------------------------------------------------

/allegro417/src/win/wdsinput.c  line 546

/* let's get the data aligned linearly */
linear_input_ptr = malloc(bytes_to_lock);
memcpy(linear_input_ptr, input_ptr1, input_bytes1);

malloc() needs to be checked for success

----------------------------------------------------
/allegro417/src/win/wgdi.c  line 470

/* create the screen surface */
screen_surf = malloc(w * h * BYTES_PER_PIXEL(color_depth));
gdi_screen = _make_bitmap(w, h, (unsigned long)screen_surf, &gfx_gdi, color_depth, w * BYTES_PER_PIXEL(color_depth));

malloc() success check needed

----------------------------------------------------------

/allegro417/src/win/wmidi.c  line 78

driver = malloc(sizeof(MIDI_DRIVER));
memcpy(driver, &_midi_none, sizeof(MIDI_DRIVER));

malloc success check needed,
same again for line 88

driver->ascii_name = malloc(strlen(caps.szPname)+1);
strcpy((char *)driver->ascii_name, caps.szPname);

----------------------------------------------------------

/allegro417/src/win/wsndwo.c  line 282

lpWaveHdr = malloc(sizeof(WAVEHDR));
lpWaveHdr->lpData = digiwobufdata;;

malloc() succes check needed

------------------------------------------------------------

/allegro417/src/win/wsystem.c

sys_directx_get_executable_name()

sanity check on 'size'
and malloc() success check needed

------------------------------------------------------------

/allegro417/src/win/wsystem.c

sys_directx_message()

malloc() success check needed
maybe check the input is != NULL

-------------------------------------------------------------

/allegro417/src/win/wsystem.c line 461

_WinMain()

argbuf = malloc(i);
memcpy(argbuf, cmdline, i);

malloc() success check needed

----------------------------------------------------------

there is a function called
_al_sane_realloc()
which says it is a replacement for realloc()
can all the realloc()'s get re-written to use it
if its going to be better

------------------------------------------------------------

/allegro/src/win/wgdi.c  line 529

free(screen_surf);

if screen_surf is an internal pointer,
shouldn't it be set to NULL after it is free'd.

and why does

gdi_screen = NULL;

in line 530?  when the preceeding line free'd something else ?

-----------------------------------------------------------

aj.



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/