Skip to content

Commit

Permalink
-Fix: check malloc() / strdup() errors
Browse files Browse the repository at this point in the history
fixes OpenDUNE#317

Signed-off-by: Thomas Bernard <[email protected]>
  • Loading branch information
miniupnp committed Jun 4, 2018
1 parent 74e2b68 commit a4e6068
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/depend/depend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ class File {
exit(1);
}
this->dirname = strdup(filename);
if (this->dirname == NULL) {
fprintf(stdout, "Error allocating %d bytes of memory\n", (int)(strlen(filename) + 1));
exit(1);
}
char *last = strrchr(this->dirname, '/');
if (last != NULL) {
*last = '\0';
Expand Down
3 changes: 3 additions & 0 deletions src/video/hqx_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

#include <stdlib.h>
#include <assert.h>
#include "hqx.h"

uint32_t * RGBtoYUV = NULL;
Expand All @@ -27,6 +28,7 @@ HQX_API void HQX_CALLCONV hqxInit(void)
uint32_t c, r, g, b, y, u, v;
#ifndef HQX_VGACOLORS
RGBtoYUV = malloc(sizeof(uint32_t) * 16777216);
assert (RGBtoYUV != NULL);

for (c = 0; c < 16777216; c++) {
r = (c & 0xFF0000) >> 16;
Expand All @@ -40,6 +42,7 @@ HQX_API void HQX_CALLCONV hqxInit(void)
#else
/* DUNE 2 is using 6bit per component colors (VGA) */
RGBtoYUV = malloc(sizeof(uint32_t) * 64*64*64);
assert (RGBtoYUV != NULL);

for (c = 0; c < 64*64*64; c++) {
r = (((c & 0x0FF000) >> 12) * 0x41) >> 4;
Expand Down

0 comments on commit a4e6068

Please sign in to comment.