ref: 83a811038aa9ec2ebfeb464d6267f5725b7e53da
parent: e334de61580e02c7fce892dd185b5c3fd7ff6e5d
parent: 9f055dbe625ad02b3ee85876ec53f059c362b1d2
author: Fabian Greffrath <[email protected]>
date: Wed Aug 23 04:01:53 EDT 2017
Merge pull request #937 from chocolate-doom/i_realloc Add an I_Realloc() function and use it instead of realloc()
--- a/HACKING.md
+++ b/HACKING.md
@@ -139,6 +139,7 @@
`strcat()` | `M_StringConcat()`
`strncat()` | `M_StringConcat()`
`strdup()` | `M_StringDuplicate()`
+`realloc()` | `I_Realloc()`
Lots of the code includes calls to DEH_String() to simulate string
replacement by the Dehacked tool. Be careful when using Dehacked
--- a/src/i_sdlmusic.c
+++ b/src/i_sdlmusic.c
@@ -472,7 +472,7 @@
{
++subst_music_len;
subst_music =
- realloc(subst_music, sizeof(subst_music_t) * subst_music_len);
+ I_Realloc(subst_music, sizeof(subst_music_t) * subst_music_len);
memcpy(&subst_music[subst_music_len - 1], subst, sizeof(subst_music_t));
}
--- a/src/i_system.c
+++ b/src/i_system.c
@@ -324,6 +324,24 @@
}
//
+// I_Realloc
+//
+
+void *I_Realloc(void *ptr, size_t size)
+{
+ void *new_ptr;
+
+ new_ptr = realloc(ptr, size);
+
+ if (size != 0 && new_ptr == NULL)
+ {
+ I_Error ("I_Realloc: failed on reallocation of %i bytes", size);
+ }
+
+ return new_ptr;
+}
+
+//
// Read Access Violation emulation.
//
// From PrBoom+, by entryway.
--- a/src/i_system.h
+++ b/src/i_system.h
@@ -56,6 +56,8 @@
void I_Tactile (int on, int off, int total);
+void *I_Realloc(void *ptr, size_t size);
+
boolean I_GetMemoryValue(unsigned int offset, void *value, int size);
// Schedule a function to be called when the program exits.
--- a/src/midifile.c
+++ b/src/midifile.c
@@ -22,6 +22,7 @@
#include "doomtype.h"
#include "i_swap.h"
+#include "i_system.h"
#include "midifile.h"
#define HEADER_CHUNK_ID "MThd"
@@ -456,14 +457,8 @@
{
// Resize the track slightly larger to hold another event:
- new_events = realloc(track->events,
+ new_events = I_Realloc(track->events,
sizeof(midi_event_t) * (track->num_events + 1));
-
- if (new_events == NULL)
- {
- return false;
- }
-
track->events = new_events;
// Read the next event:
--- a/src/net_query.c
+++ b/src/net_query.c
@@ -202,7 +202,7 @@
return NULL;
}
- targets = realloc(targets, sizeof(query_target_t) * (num_targets + 1));
+ targets = I_Realloc(targets, sizeof(query_target_t) * (num_targets + 1));
target = &targets[num_targets];
target->type = QUERY_TARGET_SERVER;
--- a/src/w_checksum.c
+++ b/src/w_checksum.c
@@ -20,6 +20,7 @@
#include <stdlib.h>
#include <string.h>
+#include "i_system.h"
#include "m_misc.h"
#include "sha1.h"
#include "w_checksum.h"
@@ -44,7 +45,7 @@
// Not found in list. This is a new file we haven't seen yet.
// Allocate another slot for this file.
- open_wadfiles = realloc(open_wadfiles,
+ open_wadfiles = I_Realloc(open_wadfiles,
sizeof(wad_file_t *) * (num_open_wadfiles + 1));
open_wadfiles[num_open_wadfiles] = handle;
--- a/src/w_wad.c
+++ b/src/w_wad.c
@@ -206,13 +206,7 @@
startlump = numlumps;
numlumps += numfilelumps;
- lumpinfo = realloc(lumpinfo, numlumps * sizeof(lumpinfo_t *));
- if (lumpinfo == NULL)
- {
- W_CloseFile(wad_file);
- I_Error("Failed to increase lumpinfo[] array size.");
- }
-
+ lumpinfo = I_Realloc(lumpinfo, numlumps * sizeof(lumpinfo_t *));
filerover = fileinfo;
for (i = startlump; i < numlumps; ++i)