use GFX2_malloc() to log allocation errors

also check malloc() return more often
This commit is contained in:
Thomas Bernard 2019-05-04 17:52:34 +02:00
parent 7f78f3ec72
commit c051ac2189
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C
8 changed files with 139 additions and 102 deletions

View File

@ -66,6 +66,7 @@ char * Bound_script[10];
#endif
#include "unicode.h"
#include "gfx2mem.h"
///
/// Number of characters for name in fileselector.
@ -2366,7 +2367,9 @@ void Run_script(const char *script_subdirectory, const char *script_filename)
/// @todo as the value doesn't vary, this should be
/// done once at the start of the program
path = malloc(strlen(Data_directory) + strlen(SCRIPTS_SUBDIRECTORY) + strlen(LUALIB_SUBDIRECTORY) + 5 + 3 * strlen(PATH_SEPARATOR) + 9 + 1);
path = GFX2_malloc(strlen(Data_directory) + strlen(SCRIPTS_SUBDIRECTORY) + strlen(LUALIB_SUBDIRECTORY) + 5 + 3 * strlen(PATH_SEPARATOR) + 9 + 1);
if (path == NULL)
return;
strcpy(path, Data_directory);
Append_path(path, SCRIPTS_SUBDIRECTORY, NULL);
Append_path(path, LUALIB_SUBDIRECTORY, NULL);
@ -2495,7 +2498,7 @@ void Run_script(const char *script_subdirectory, const char *script_filename)
Original_fore_color=Fore_color;
// Backup the brush
Brush_backup=(byte *)malloc(((long)Brush_height)*Brush_width);
Brush_backup=(byte *)GFX2_malloc(((long)Brush_height)*Brush_width);
Brush_backup_width = Brush_width;
Brush_backup_height = Brush_height;

View File

@ -21,6 +21,7 @@
#include <stdlib.h>
#include <string.h>
#include "gfx2surface.h"
#include "gfx2mem.h"
#include "errors.h"
T_GFX2_Surface * New_GFX2_Surface(word width, word height)
@ -32,10 +33,10 @@ T_GFX2_Surface * New_GFX2_Surface(word width, word height)
if (size == 0) // surfaces with no pixels not allowed
return NULL;
surface = malloc(sizeof(T_GFX2_Surface));
surface = GFX2_malloc(sizeof(T_GFX2_Surface));
if (surface == NULL)
return NULL;
surface->pixels = malloc(size);
surface->pixels = GFX2_malloc(size);
if(surface->pixels == NULL)
{
free(surface);

View File

@ -67,6 +67,7 @@
#endif
#endif
#include "gfx2mem.h"
#include "buttons.h"
#include "const.h"
#include "errors.h"
@ -667,20 +668,18 @@ T_Gui_skin * Load_graphics(const char * skin_file, T_Gradient_array *gradients)
return NULL;
}
gfx = (T_Gui_skin *)malloc(sizeof(T_Gui_skin));
gfx = (T_Gui_skin *)GFX2_malloc(sizeof(T_Gui_skin));
if (gfx == NULL)
{
GFX2_Log(GFX2_ERROR, "Failed to allocate %lu bytes\n", (unsigned long)sizeof(T_Gui_skin));
sprintf(Gui_loading_error_message, "Not enough memory to read skin file\n");
return NULL;
}
// Read the "skin" file
len = strlen(Data_directory) + strlen(SKINS_SUBDIRECTORY) + strlen(PATH_SEPARATOR) + strlen(skin_file) + 1;
filename = malloc(len);
filename = GFX2_malloc(len);
if (filename == NULL)
{
GFX2_Log(GFX2_ERROR, "Failed to allocate %lu bytes\n", (unsigned long)len);
free(gfx);
return NULL;
}
@ -728,7 +727,7 @@ static byte * Parse_font(T_GFX2_Surface * image, int is_main)
sprintf(Gui_loading_error_message, "Error in font file: Image is too small to be a 256-character 8x8 font.\n");
return NULL;
}
font = (byte *)malloc(8*8*character_count);
font = (byte *)GFX2_malloc(8*8*character_count);
if (font == NULL)
{
sprintf(Gui_loading_error_message, "Not enough memory to read font file\n");
@ -773,12 +772,9 @@ byte * Load_font(const char * font_name, int is_main)
// Read the file containing the image
len = strlen(Data_directory) + strlen(SKINS_SUBDIRECTORY) + strlen(PATH_SEPARATOR) + strlen(font_name) + 1;
filename = malloc(len);
filename = GFX2_malloc(len);
if (filename == NULL)
{
GFX2_Log(GFX2_ERROR, "Failed to allocate %lu bytes\n", len);
return NULL;
}
snprintf(filename, len, "%s%s%s%s", Data_directory, SKINS_SUBDIRECTORY, PATH_SEPARATOR, font_name);
image = Load_surface(filename, NULL);
@ -808,12 +804,15 @@ static void Load_Unicode_font(const char * fullname, const char * filename)
font = Load_font(filename, 0);
if (font)
{
ufont = malloc(sizeof(T_Unicode_Font));
ufont->FirstChar = first;
ufont->LastChar = last;
ufont->FontData = font;
ufont->Next = Unicode_fonts;
Unicode_fonts = ufont;
ufont = GFX2_malloc(sizeof(T_Unicode_Font));
if (ufont != NULL)
{
ufont->FirstChar = first;
ufont->LastChar = last;
ufont->FontData = font;
ufont->Next = Unicode_fonts;
Unicode_fonts = ufont;
}
}
}
else
@ -1955,8 +1954,8 @@ int Load_CFG(int reload_all)
if (size!=0)
{
// Alloc string
Bound_script[current_script]=malloc(size+1);
if (Bound_script[current_script]==NULL)
Bound_script[current_script] = GFX2_malloc(size+1);
if (Bound_script[current_script] == NULL)
return ERROR_MEMORY;
// Init and load string

View File

@ -68,6 +68,7 @@
#include "unicode.h"
#include "global.h"
#include "gfx2log.h"
#include "gfx2mem.h"
// Lit un octet
// Renvoie -1 si OK, 0 en cas d'erreur
@ -307,7 +308,7 @@ char * Filepath_append_to_dir(const char * dir, const char * filename)
)
{
len += strlen(filename) + 1;
path = malloc(len);
path = GFX2_malloc(len);
if (path == NULL)
return NULL;
snprintf(path, len, "%s%s", dir, filename);
@ -316,7 +317,7 @@ char * Filepath_append_to_dir(const char * dir, const char * filename)
{
// need to add a path separator
len += strlen(PATH_SEPARATOR) + strlen(filename) + 1;
path = malloc(len);
path = GFX2_malloc(len);
if (path == NULL)
return NULL;
snprintf(path, len, "%s%s%s", dir, PATH_SEPARATOR, filename);
@ -655,7 +656,9 @@ void For_each_directory_entry(const char * directory_name, void * pdata, T_File_
HANDLE h;
len = strlen(directory_name) + 3;
search_string = (word *)malloc(sizeof(word) * len);
search_string = (word *)GFX2_malloc(sizeof(word) * len);
if (search_string == NULL)
return;
Unicode_char_strlcpy(search_string, directory_name, len);
Unicode_char_strlcat(search_string, "\\*", len);
h = FindFirstFileW((WCHAR *)search_string, &fd);
@ -708,19 +711,22 @@ void For_each_directory_entry(const char * directory_name, void * pdata, T_File_
size_t outbytesleft;
size_t r;
unicode_filename = malloc(sizeof(word) * (inbytesleft + 1));
output = (char *)unicode_filename;
outbytesleft = sizeof(word) * inbytesleft;
r = iconv(cd_utf16, &input, &inbytesleft, &output, &outbytesleft);
if (r != (size_t)-1)
unicode_filename = GFX2_malloc(sizeof(word) * (inbytesleft + 1));
if (unicode_filename != NULL)
{
output[0] = '\0';
output[1] = '\0';
}
else
{
free(unicode_filename);
unicode_filename = NULL;
output = (char *)unicode_filename;
outbytesleft = sizeof(word) * inbytesleft;
r = iconv(cd_utf16, &input, &inbytesleft, &output, &outbytesleft);
if (r != (size_t)-1)
{
output[0] = '\0';
output[1] = '\0';
}
else
{
free(unicode_filename);
unicode_filename = NULL;
}
}
}
#endif
@ -765,7 +771,9 @@ word * Get_Unicode_Filename(word * filename_unicode, const char * filename, cons
WCHAR * longPath;
WCHAR * sep;
shortPath = (WCHAR *)malloc(sizeof(WCHAR) * (strlen(filename) + strlen(directory) + 2));
shortPath = (WCHAR *)GFX2_malloc(sizeof(WCHAR) * (strlen(filename) + strlen(directory) + 2));
if (shortPath == NULL)
return NULL;
// copy the full path to a wide character buffer :
while (directory[0] != '\0')
shortPath[i++] = *directory++;
@ -780,8 +788,8 @@ word * Get_Unicode_Filename(word * filename_unicode, const char * filename, cons
free(shortPath);
return NULL;
}
longPath = (WCHAR *)malloc(len * sizeof(WCHAR));
if (GetLongPathNameW(shortPath, longPath, len) == 0)
longPath = (WCHAR *)GFX2_malloc(len * sizeof(WCHAR));
if (longPath == NULL || GetLongPathNameW(shortPath, longPath, len) == 0)
{
free(shortPath);
return NULL;
@ -799,8 +807,9 @@ word * Get_Unicode_Filename(word * filename_unicode, const char * filename, cons
sep++;
len = wcslen(sep) + 1;
if (filename_unicode == NULL)
filename_unicode = (word *)malloc(sizeof(word) * len);
memcpy(filename_unicode, sep, sizeof(word) * len);
filename_unicode = (word *)GFX2_malloc(sizeof(word) * len);
if (filename_unicode != NULL)
memcpy(filename_unicode, sep, sizeof(word) * len);
}
free(longPath);
return filename_unicode;
@ -817,7 +826,7 @@ word * Get_Unicode_Filename(word * filename_unicode, const char * filename, cons
return NULL;
if (filename_unicode == NULL)
{
filename_unicode = malloc(sizeof(word) * (inbytesleft + 1));
filename_unicode = GFX2_malloc(sizeof(word) * (inbytesleft + 1));
if (filename_unicode == NULL)
return NULL;
allocated_memory = 1;
@ -936,7 +945,11 @@ char * Get_current_directory(char * buf, word * * unicode, size_t size)
{
#if defined(__MINT__)
if (buf == NULL)
buf = malloc(MAX_PATH_CHARACTERS);
{
buf = GFX2_malloc(MAX_PATH_CHARACTERS);
if (buf == NULL)
return NULL;
}
buf[0] = 'A'+Dgetdrv();
buf[1] = ':';
buf[2] = '\\';
@ -953,18 +966,15 @@ char * Get_current_directory(char * buf, word * * unicode, size_t size)
size = (size_t)GetCurrentDirectoryA(0, NULL);
if (size == 0)
return NULL;
buf = (char *)malloc(size);
buf = (char *)GFX2_malloc(size);
if (buf == NULL)
{
GFX2_Log(GFX2_ERROR, "Failed to allocate %lu bytes.\n", (unsigned long)size);
return NULL;
}
}
if (GetCurrentDirectoryA(size, buf) == 0)
return NULL;
if (unicode != NULL)
{
WCHAR * temp = (WCHAR *)malloc(sizeof(WCHAR) * size);
WCHAR * temp = (WCHAR *)GFX2_malloc(sizeof(WCHAR) * size);
if (temp != NULL)
{
size_t i;
@ -972,8 +982,9 @@ char * Get_current_directory(char * buf, word * * unicode, size_t size)
temp[i] = (WCHAR)buf[i] & 0x00ff;
temp[i] = 0;
size = GetLongPathNameW(temp, NULL, 0);
*unicode = (word *)malloc(size*sizeof(word));
GetLongPathNameW(temp, (WCHAR *)*unicode, size);
*unicode = (word *)GFX2_malloc(size*sizeof(word));
if (*unicode != NULL)
GetLongPathNameW(temp, (WCHAR *)*unicode, size);
free(temp);
}
}
@ -987,7 +998,7 @@ char * Get_current_directory(char * buf, word * * unicode, size_t size)
{
char * input = ret;
size_t inbytesleft = strlen(ret);
word * buf_unicode = malloc((inbytesleft + 1) * 2);
word * buf_unicode = GFX2_malloc((inbytesleft + 1) * 2);
char * output = (char *)buf_unicode;
size_t outbytesleft = 2 * inbytesleft;
if (cd_utf16 != (iconv_t)-1 && buf_unicode != NULL)
@ -1100,16 +1111,18 @@ char * Calculate_relative_path(const char * ref_path, const char * path)
{
free(real_ref_path);
len = strlen(path + i) + 1;
rel_path = malloc(len + 1);
snprintf(rel_path, len, ".%s", path + i);
rel_path = GFX2_malloc(len + 1);
if (rel_path != NULL)
snprintf(rel_path, len, ".%s", path + i);
return rel_path;
}
else if (i > 0 && real_ref_path[i - 1] == PATH_SEPARATOR[0])
{
free(real_ref_path);
len = strlen(path + i - 1) + 1;
rel_path = malloc(len + 1);
snprintf(rel_path, len, ".%s", path + i - 1);
rel_path = GFX2_malloc(len + 1);
if (rel_path != NULL)
snprintf(rel_path, len, ".%s", path + i - 1);
return rel_path;
}
}
@ -1128,10 +1141,13 @@ char * Calculate_relative_path(const char * ref_path, const char * path)
i = 0;
// construct the relative path
len = separator_count * (2 + strlen(PATH_SEPARATOR)) + strlen(path + last_separator + 1) + 1;
rel_path = malloc(len + 1);
while(separator_count-- > 0)
i += snprintf(rel_path + i, len + 1 - i, "..%s", PATH_SEPARATOR);
strncpy(rel_path + i, path + last_separator + 1, len + 1 - i);
rel_path[len] = '\0';
rel_path = GFX2_malloc(len + 1);
if (rel_path != NULL)
{
while(separator_count-- > 0)
i += snprintf(rel_path + i, len + 1 - i, "..%s", PATH_SEPARATOR);
strncpy(rel_path + i, path + last_separator + 1, len + 1 - i);
rel_path[len] = '\0';
}
return rel_path;
}

View File

@ -52,6 +52,7 @@
#endif
#include "gfx2log.h"
#include "gfx2mem.h"
#include "buttons.h"
#include "const.h"
#include "errors.h"
@ -501,7 +502,7 @@ void Pre_load(T_IO_Context *context, short width, short height, long file_size,
break;
case CONTEXT_BRUSH:
context->Buffer_image = (byte *)malloc(width*height);
context->Buffer_image = (byte *)GFX2_malloc(width*height);
if (! context->Buffer_image)
{
File_error=3;
@ -540,8 +541,8 @@ void Pre_load(T_IO_Context *context, short width, short height, long file_size,
case CONTEXT_BRUSH:
case CONTEXT_SURFACE:
// Allocate 24bit buffer
context->Buffer_image_24b=
(T_Components *)malloc(width*height*sizeof(T_Components));
context->Buffer_image_24b =
(T_Components *)GFX2_malloc(width*height*sizeof(T_Components));
if (!context->Buffer_image_24b)
{
// Print an error message
@ -1950,7 +1951,7 @@ static void Add_backup_file(const char * full_name, const char *file_name)
}
// Add to list (top insertion)
elem = (T_String_list *)malloc(sizeof(T_String_list));
elem = (T_String_list *)GFX2_malloc(sizeof(T_String_list));
elem->String=strdup(file_name);
elem->Next=*list;
*list=elem;
@ -1991,7 +1992,8 @@ byte Process_backups(T_String_list **list)
element = element->Next;
}
// Allocate a vector
files_vector = (char **)malloc(sizeof(char *) * nb_files);
files_vector = (char **)GFX2_malloc(sizeof(char *) * nb_files);
// TODO
// Copy from list to vector
for (i=0;i<nb_files;i++)
{
@ -2109,12 +2111,9 @@ void Rotate_safety_backups(void)
char * deleted_file;
size_t len = strlen(Config_directory) + strlen(BACKUP_FILE_EXTENSION) + 1 + 6 + 1;
deleted_file = malloc(len);
deleted_file = GFX2_malloc(len);
if (deleted_file == NULL)
{
GFX2_Log(GFX2_ERROR, "Failed to allocate %lu bytes.\n", (unsigned long)len);
return;
}
// Clear a previous save (rotating saves)
snprintf(deleted_file, len, "%s%c%6.6d" BACKUP_FILE_EXTENSION,
Config_directory,
@ -2200,7 +2199,9 @@ FILE * Open_file_write(T_IO_Context *context)
len = strlen(context->File_directory) + strlen(PATH_SEPARATOR)
+ Unicode_strlen(context->File_name_unicode) + 1;
filename_unicode = (WCHAR *)malloc(sizeof(WCHAR) * len);
filename_unicode = (WCHAR *)GFX2_malloc(sizeof(WCHAR) * len);
if (filename_unicode == NULL)
return NULL;
Unicode_char_strlcpy((word *)filename_unicode, context->File_directory, len);
Unicode_char_strlcat((word *)filename_unicode, PATH_SEPARATOR, len);
@ -2213,17 +2214,23 @@ FILE * Open_file_write(T_IO_Context *context)
len = GetShortPathNameW(filename_unicode, NULL, 0);
if (len > 0)
{
WCHAR * shortpath = (WCHAR *)malloc(sizeof(WCHAR) * len);
len = GetShortPathNameW(filename_unicode, shortpath, len);
if (len > 0)
WCHAR * shortpath = (WCHAR *)GFX2_malloc(sizeof(WCHAR) * len);
if (shortpath != NULL)
{
DWORD start, index;
for (start = len; start > 0 && shortpath[start-1] != '\\'; start--);
free(context->File_name);
context->File_name = (char *)malloc(len + 1 - start);
for (index = 0; index < len - start; index++)
context->File_name[index] = shortpath[start + index];
context->File_name[index] = '\0';
len = GetShortPathNameW(filename_unicode, shortpath, len);
if (len > 0)
{
DWORD start, index;
for (start = len; start > 0 && shortpath[start-1] != '\\'; start--);
free(context->File_name);
context->File_name = (char *)GFX2_malloc(len + 1 - start);
if (context->File_name != NULL)
{
for (index = 0; index < len - start; index++)
context->File_name[index] = shortpath[start + index];
context->File_name[index] = '\0';
}
}
}
}
}
@ -2233,6 +2240,8 @@ FILE * Open_file_write(T_IO_Context *context)
#endif
filename = Filepath_append_to_dir(context->File_directory, context->File_name);
if (filename == NULL)
return NULL;
f = fopen(filename, "wb");
free(filename);
return f;
@ -2252,7 +2261,9 @@ FILE * Open_file_write_with_alternate_ext(T_IO_Context *context, const char * ex
len = strlen(context->File_directory) + strlen(PATH_SEPARATOR)
+ Unicode_strlen(context->File_name_unicode) + strlen(ext) + 1 + 1;
filename_unicode = (WCHAR *)malloc(len * sizeof(WCHAR));
filename_unicode = (WCHAR *)GFX2_malloc(len * sizeof(WCHAR));
if (filename_unicode == NULL)
return NULL;
Unicode_char_strlcpy((word *)filename_unicode, context->File_directory, len);
Unicode_char_strlcat((word *)filename_unicode, PATH_SEPARATOR, len);
Unicode_strlcat((word *)filename_unicode, context->File_name_unicode, len);
@ -2323,7 +2334,9 @@ static void Look_for_alternate_ext(void * pdata, const char * filename, const wo
#if defined(WIN32)
{
int cmp;
WCHAR * temp_string = (WCHAR *)malloc((base_len + 1) * sizeof(WCHAR));
WCHAR * temp_string = (WCHAR *)GFX2_malloc((base_len + 1) * sizeof(WCHAR));
if (temp_string == NULL)
return;
memcpy(temp_string, filename_unicode, base_len * sizeof(word));
temp_string[base_len] = 0;
cmp = _wcsicmp((const WCHAR *)params->basename_unicode, temp_string);
@ -2383,12 +2396,8 @@ FILE * Open_file_read_with_alternate_ext(T_IO_Context *context, const char * ext
if (context->File_name_unicode != NULL)
{
size_t i = Unicode_strlen(context->File_name_unicode);
params.basename_unicode = malloc(sizeof(word) * (i + 1));
if (params.basename_unicode == NULL)
{
GFX2_Log(GFX2_ERROR, "Open_file_read_with_alternate_ext() failed to allocate %lu bytes\n", (unsigned long)(sizeof(word) * (i + 1)));
}
else
params.basename_unicode = GFX2_malloc(sizeof(word) * (i + 1));
if (params.basename_unicode != NULL)
{
memcpy(params.basename_unicode, context->File_name_unicode, (i + 1) * sizeof(word));
while (i-- > 0)

View File

@ -104,6 +104,7 @@
#endif
#include "gfx2log.h"
#include "gfx2mem.h"
#include "const.h"
#include "struct.h"
#include "global.h"
@ -649,8 +650,8 @@ int Init_program(int argc,char * argv[])
// principale et la page de brouillon afin que leurs champs ne soient pas
// invalide lors des appels aux multiples fonctions manipulées à
// l'initialisation du programme.
Main.backups=(T_List_of_pages *)malloc(sizeof(T_List_of_pages));
Spare.backups=(T_List_of_pages *)malloc(sizeof(T_List_of_pages));
Main.backups=(T_List_of_pages *)GFX2_malloc(sizeof(T_List_of_pages));
Spare.backups=(T_List_of_pages *)GFX2_malloc(sizeof(T_List_of_pages));
Init_list_of_pages(Main.backups);
Init_list_of_pages(Spare.backups);
@ -870,7 +871,9 @@ int Init_program(int argc,char * argv[])
Windows_open=0;
// Paintbrush
if (!(Paintbrush_sprite=(byte *)malloc(MAX_PAINTBRUSH_SIZE*MAX_PAINTBRUSH_SIZE))) Error(ERROR_MEMORY);
Paintbrush_sprite = (byte *)GFX2_malloc(MAX_PAINTBRUSH_SIZE*MAX_PAINTBRUSH_SIZE);
if (!Paintbrush_sprite)
Error(ERROR_MEMORY);
// Load preset paintbrushes (uses Paintbrush_ variables)
Init_paintbrushes();
@ -959,8 +962,12 @@ int Init_program(int argc,char * argv[])
Back_color=Best_color_range(0,0,0,Config.Palette_cells_X*Config.Palette_cells_Y);
// Allocation de mémoire pour la brosse
if (!(Brush =(byte *)malloc( 1* 1))) Error(ERROR_MEMORY);
if (!(Smear_brush =(byte *)malloc(MAX_PAINTBRUSH_SIZE*MAX_PAINTBRUSH_SIZE))) Error(ERROR_MEMORY);
Brush = (byte *)GFX2_malloc(1*1);
if (!Brush)
Error(ERROR_MEMORY);
Smear_brush = (byte *)GFX2_malloc(MAX_PAINTBRUSH_SIZE*MAX_PAINTBRUSH_SIZE);
if (!Smear_brush)
Error(ERROR_MEMORY);
starting_videomode=Current_resolution;

View File

@ -30,6 +30,7 @@
#define strdup _strdup
#endif
#include "gfx2mem.h"
#include "global.h"
#include "pages.h"
#include "errors.h"
@ -66,7 +67,7 @@ T_Page * New_page(int nb_layers)
{
T_Page * page;
page = (T_Page *)malloc(sizeof(T_Page)+nb_layers*sizeof(T_Image));
page = (T_Page *)GFX2_malloc(sizeof(T_Page)+nb_layers*sizeof(T_Image));
if (page!=NULL)
{
int i;
@ -107,7 +108,7 @@ T_Page * New_page(int nb_layers)
/// Allocate a new layer
byte * New_layer(long pixel_size)
{
short * ptr = malloc(sizeof(short)+pixel_size);
short * ptr = GFX2_malloc(sizeof(short)+pixel_size);
if (ptr==NULL)
return NULL;
@ -715,7 +716,7 @@ int Update_buffers(int width, int height)
{
// Current image
free(Main.visible_image.Image);
Main.visible_image.Image = (byte *)malloc(width * height);
Main.visible_image.Image = (byte *)GFX2_malloc(width * height);
if (Main.visible_image.Image == NULL)
return 0;
}
@ -726,7 +727,7 @@ int Update_buffers(int width, int height)
{
// Previous image
free(Main_visible_image_backup.Image);
Main_visible_image_backup.Image = (byte *)malloc(width * height);
Main_visible_image_backup.Image = (byte *)GFX2_malloc(width * height);
if (Main_visible_image_backup.Image == NULL)
return 0;
}
@ -737,7 +738,7 @@ int Update_buffers(int width, int height)
{
// Depth buffer
free(Main_visible_image_depth_buffer.Image);
Main_visible_image_depth_buffer.Image = (byte *)malloc(width * height);
Main_visible_image_depth_buffer.Image = (byte *)GFX2_malloc(width * height);
if (Main_visible_image_depth_buffer.Image == NULL)
return 0;
}
@ -757,7 +758,7 @@ int Update_spare_buffers(int width, int height)
{
// Current image
free(Spare.visible_image.Image);
Spare.visible_image.Image = (byte *)malloc(width * height);
Spare.visible_image.Image = (byte *)GFX2_malloc(width * height);
if (Spare.visible_image.Image == NULL)
return 0;
}
@ -1022,7 +1023,7 @@ int Backup_in_place(int width,int height)
{
// Current image
free(Main.visible_image.Image);
Main.visible_image.Image = (byte *)malloc(width * height);
Main.visible_image.Image = (byte *)GFX2_malloc(width * height);
if (Main.visible_image.Image == NULL)
return 0;
}
@ -1033,7 +1034,7 @@ int Backup_in_place(int width,int height)
{
// Depth buffer
free(Main_visible_image_depth_buffer.Image);
Main_visible_image_depth_buffer.Image = (byte *)malloc(width * height);
Main_visible_image_depth_buffer.Image = (byte *)GFX2_malloc(width * height);
if (Main_visible_image_depth_buffer.Image == NULL)
return 0;
}

View File

@ -22,6 +22,7 @@
#include <stdlib.h>
#include <string.h>
#include "gfx2mem.h"
#include "unicode.h"
size_t Unicode_strlen(const word * str)
@ -43,7 +44,7 @@ word * Unicode_strdup(const word * str)
if (str == NULL)
return NULL;
byte_size = Unicode_strlen(str) * 2 + 2;
new_str = malloc(byte_size);
new_str = GFX2_malloc(byte_size);
if (new_str != NULL)
memcpy(new_str, str, byte_size);
return new_str;