diff --git a/2dlib/font.cpp b/2dlib/font.cpp index ba4ea214..5618661f 100644 --- a/2dlib/font.cpp +++ b/2dlib/font.cpp @@ -415,7 +415,7 @@ void grFont::load(char *filename, int slot) { // generate character data pointer table int bytesize = READ_FONT_INT(ff); - ft->raw_data = (uint8_t *)mem_malloc(bytesize); + ft->raw_data = mem_rmalloc(bytesize); ft->char_data = mem_rmalloc(num_char); READ_FONT_DATA(ff, ft->raw_data, bytesize, 1); diff --git a/Descent3/LoadLevel.cpp b/Descent3/LoadLevel.cpp index b67582a3..f38d3517 100644 --- a/Descent3/LoadLevel.cpp +++ b/Descent3/LoadLevel.cpp @@ -2568,7 +2568,7 @@ int ReadRoom(CFILE *ifile, room *rp, int version) { if (size) { - rp->volume_lights = (uint8_t *)mem_malloc(size); + rp->volume_lights = mem_rmalloc(size); ASSERT(rp->volume_lights); // ran out of memory! } else rp->volume_lights = NULL; @@ -3138,7 +3138,7 @@ void ReadRoomAABBChunk(CFILE *fp, int version) { Rooms[i].bbf_list = mem_rmalloc(Rooms[i].num_bbf_regions); Rooms[i].bbf_list_min_xyz = mem_rmalloc(Rooms[i].num_bbf_regions); Rooms[i].bbf_list_max_xyz = mem_rmalloc(Rooms[i].num_bbf_regions); - Rooms[i].bbf_list_sector = (uint8_t *)mem_malloc(sizeof(char) * Rooms[i].num_bbf_regions); + Rooms[i].bbf_list_sector = mem_rmalloc(sizeof(char) * Rooms[i].num_bbf_regions); for (j = 0; j < Rooms[i].num_bbf_regions; j++) { Rooms[i].num_bbf[j] = cf_ReadShort(fp); @@ -4079,8 +4079,8 @@ int LoadLevel(char *filename, void (*cb_fn)(const char *, int, int)) { // share 1 lightmap if (version >= 34 && !Dedicated_server) { - uint8_t *lightmap_spoken_for = (uint8_t *)mem_malloc(MAX_LIGHTMAPS); - uint8_t *free_lightmap_info = (uint8_t *)mem_malloc(MAX_LIGHTMAP_INFOS); + uint8_t *lightmap_spoken_for = mem_rmalloc(MAX_LIGHTMAPS); + uint8_t *free_lightmap_info = mem_rmalloc(MAX_LIGHTMAP_INFOS); ASSERT(lightmap_spoken_for); memset(lightmap_spoken_for, 0, MAX_LIGHTMAPS); @@ -4885,7 +4885,7 @@ void WriteLightmapChunk(CFILE *fp) { int lightmap_count = 0; uint16_t *lightmap_remap = mem_rmalloc(MAX_LIGHTMAPS); - uint8_t *lightmap_spoken_for = (uint8_t *)mem_malloc(MAX_LIGHTMAPS); + uint8_t *lightmap_spoken_for = mem_rmalloc(MAX_LIGHTMAPS); ASSERT(lightmap_remap); ASSERT(lightmap_spoken_for); diff --git a/Descent3/TelComAutoMap.cpp b/Descent3/TelComAutoMap.cpp index 2f0b030a..d884a770 100644 --- a/Descent3/TelComAutoMap.cpp +++ b/Descent3/TelComAutoMap.cpp @@ -207,7 +207,7 @@ void ClassifyAMFaces() { int i = 0; for (i = 0; i <= Highest_room_index; i++) { if (Rooms[i].used) { - Small_faces[i] = (uint8_t *)mem_malloc(Rooms[i].num_faces); + Small_faces[i] = mem_rmalloc(Rooms[i].num_faces); ASSERT(Small_faces[i]); memset(Small_faces[i], 0, Rooms[i].num_faces); diff --git a/Descent3/audiotaunts.cpp b/Descent3/audiotaunts.cpp index 4e5b21e2..18d04bb6 100644 --- a/Descent3/audiotaunts.cpp +++ b/Descent3/audiotaunts.cpp @@ -368,7 +368,7 @@ bool taunt_ImportWave(const char *wave_filename, const char *outputfilename) { uint32_t filelen, nblocks, i; int format; - StaticFileBuffer = (uint8_t *)mem_malloc(FILEBUFFER_LENGTH); + StaticFileBuffer = mem_rmalloc(FILEBUFFER_LENGTH); if (!StaticFileBuffer) { ret = false; LOG_ERROR << "Out of memory"; @@ -710,7 +710,7 @@ char taunt_LoadWaveFile(const char *filename, tWaveFile *wave) { wave->sample_length = aligned_size; wave->np_sample_length = cksize; - wave->sample_8bit = (uint8_t *)mem_malloc(aligned_size); + wave->sample_8bit = mem_rmalloc(aligned_size); cf_ReadBytes((uint8_t *)wave->sample_8bit, cksize, cfptr); diff --git a/Descent3/room.cpp b/Descent3/room.cpp index 47f7d241..43b06367 100644 --- a/Descent3/room.cpp +++ b/Descent3/room.cpp @@ -496,7 +496,7 @@ void RoomMemInit(int nverts, int nfaces, int nfaceverts, int nportals) { if (Room_mem_buf) mem_free(Room_mem_buf); - Room_mem_buf = (uint8_t *)mem_malloc(size); + Room_mem_buf = mem_rmalloc(size); Room_mem_size = size; Room_mem_ptr = Room_mem_buf; diff --git a/Descent3/terrain.cpp b/Descent3/terrain.cpp index 4b707a57..a8aaf527 100644 --- a/Descent3/terrain.cpp +++ b/Descent3/terrain.cpp @@ -823,7 +823,7 @@ int LoadPCXTerrain(char *filename) { total = width * height; - lando = (uint8_t *)mem_malloc(total); + lando = mem_rmalloc(total); LOG_DEBUG.printf("Heightmap is %d x %d", width, height); diff --git a/editor/TerrainDialog.cpp b/editor/TerrainDialog.cpp index 9c02cce1..0a6ce2d6 100644 --- a/editor/TerrainDialog.cpp +++ b/editor/TerrainDialog.cpp @@ -1750,7 +1750,7 @@ void CTerrainDialog::OnTerrainOcclusion() { for (int i = 0; i < 256; i++) { memset(Terrain_occlusion_map[i], 0, 32); - touch_buffer[i] = (uint8_t *)mem_malloc(256); + touch_buffer[i] = mem_rmalloc(256); ASSERT(touch_buffer[i]); memset(touch_buffer[i], 255, 256); } diff --git a/editor/editor_lighting.cpp b/editor/editor_lighting.cpp index 50589366..ba2cd222 100644 --- a/editor/editor_lighting.cpp +++ b/editor/editor_lighting.cpp @@ -422,7 +422,7 @@ void SqueezeLightmaps(int external, int target_roomnum) { int i, t, k; mprintf(0, "Squeezing %s lightmaps, please wait...\n", external ? "external" : "internal"); - Lmi_spoken_for = (uint8_t *)mem_malloc(MAX_LIGHTMAP_INFOS); + Lmi_spoken_for = mem_rmalloc(MAX_LIGHTMAP_INFOS); Lightmap_mask = (uint8_t *)mem_malloc(128 * 128); Squeeze_lightmap_handle = -1; @@ -2927,7 +2927,7 @@ void ComputeAllRoomLightmapUVs(int external) { if (!external && (Rooms[i].flags & RF_EXTERNAL)) continue; - RoomsAlreadyCombined[i] = (uint8_t *)mem_malloc(Rooms[i].num_faces); + RoomsAlreadyCombined[i] = mem_rmalloc(Rooms[i].num_faces); ASSERT(RoomsAlreadyCombined[i]); for (k = 0; k < Rooms[i].num_faces; k++) RoomsAlreadyCombined[i][k] = 0; diff --git a/editor/editor_object_lighting.cpp b/editor/editor_object_lighting.cpp index 50f1b4d3..a91e5c8e 100644 --- a/editor/editor_object_lighting.cpp +++ b/editor/editor_object_lighting.cpp @@ -959,7 +959,7 @@ void CombineObjectLightmapUVs(object *obj, int lmi_type) { if (IsNonRenderableSubmodel(pm, i)) continue; - ObjectsAlreadyCombined[i] = (uint8_t *)mem_malloc(sm->num_faces); + ObjectsAlreadyCombined[i] = mem_rmalloc(sm->num_faces); ASSERT(ObjectsAlreadyCombined[i]); for (k = 0; k < sm->num_faces; k++) ObjectsAlreadyCombined[i][k] = 0; diff --git a/grtext/grfont.cpp b/grtext/grfont.cpp index 28231601..3abcd72e 100644 --- a/grtext/grfont.cpp +++ b/grtext/grfont.cpp @@ -341,7 +341,7 @@ int grfont_Load(const char *fname) { // Read in kerning data if (fnt.flags & FT_KERNED) { int n_pairs = (int)READ_FONT_SHORT(ff); - fnt.kern_data = (uint8_t *)mem_malloc(sizeof(uint8_t) * 3 * (n_pairs + 1)); + fnt.kern_data = mem_rmalloc(sizeof(uint8_t) * 3 * (n_pairs + 1)); for (i = 0; i < n_pairs; i++) { fnt.kern_data[i * 3] = READ_FONT_BYTE(ff); fnt.kern_data[i * 3 + 1] = READ_FONT_BYTE(ff); @@ -361,7 +361,7 @@ int grfont_Load(const char *fname) { // generate character data pointer table int bytesize = READ_FONT_INT(ff); - fnt.raw_data = (uint8_t *)mem_malloc(bytesize); + fnt.raw_data = mem_rmalloc(bytesize); fnt.char_data = mem_rmalloc(num_char); READ_FONT_DATA(ff, fnt.raw_data, bytesize, 1); @@ -486,7 +486,7 @@ bool grfont_LoadTemplate(const char *fname, tFontTemplate *ft) { // Read in all widths if (ft_flags & FT_PROPORTIONAL) { - ft->ch_widths = (uint8_t *)mem_malloc(num_char); + ft->ch_widths = mem_rmalloc(num_char); for (i = 0; i < num_char; i++) ft->ch_widths[i] = (uint8_t)READ_FONT_SHORT(ff); } else { @@ -495,7 +495,7 @@ bool grfont_LoadTemplate(const char *fname, tFontTemplate *ft) { if (ft_flags & FT_KERNED) { int n_pairs = (int)READ_FONT_SHORT(ff); - ft->kern_data = (uint8_t *)mem_malloc(sizeof(uint8_t) * 3 * (n_pairs + 1)); + ft->kern_data = mem_rmalloc(sizeof(uint8_t) * 3 * (n_pairs + 1)); for (i = 0; i < n_pairs; i++) { ft->kern_data[i * 3] = READ_FONT_BYTE(ff); ft->kern_data[i * 3 + 1] = READ_FONT_BYTE(ff); @@ -588,7 +588,7 @@ bool grfont_SetTemplate(const char *pathname, const tFontTemplate *ft) { // Read in kerning data if (fnt.flags & FT_KERNED) { int n_pairs = (int)READ_FONT_SHORT(ffin); - fnt.kern_data = (uint8_t *)mem_malloc(sizeof(uint8_t) * 3 * (n_pairs + 1)); + fnt.kern_data = mem_rmalloc(sizeof(uint8_t) * 3 * (n_pairs + 1)); for (i = 0; i < n_pairs; i++) { fnt.kern_data[i * 3] = READ_FONT_BYTE(ffin); fnt.kern_data[i * 3 + 1] = READ_FONT_BYTE(ffin); @@ -604,7 +604,7 @@ bool grfont_SetTemplate(const char *pathname, const tFontTemplate *ft) { // Read in pixel data. int bytesize = READ_FONT_INT(ffin); - fnt.raw_data = (uint8_t *)mem_malloc(bytesize); + fnt.raw_data = mem_rmalloc(bytesize); READ_FONT_DATA(ffin, fnt.raw_data, bytesize, 1); diff --git a/legacy/renderer/opengl.cpp b/legacy/renderer/opengl.cpp index 569db09e..0683a464 100644 --- a/legacy/renderer/opengl.cpp +++ b/legacy/renderer/opengl.cpp @@ -281,9 +281,9 @@ int opengl_InitCache() { OpenGL_lightmap_remap = (uint16_t *)mem_malloc(MAX_LIGHTMAPS * 2); ASSERT(OpenGL_lightmap_remap); - OpenGL_bitmap_states = (uint8_t *)mem_malloc(MAX_BITMAPS); + OpenGL_bitmap_states = mem_rmalloc(MAX_BITMAPS); ASSERT(OpenGL_bitmap_states); - OpenGL_lightmap_states = (uint8_t *)mem_malloc(MAX_LIGHTMAPS); + OpenGL_lightmap_states = mem_rmalloc(MAX_LIGHTMAPS); ASSERT(OpenGL_lightmap_states); Cur_texture_object_num = 1; diff --git a/manage/manage.cpp b/manage/manage.cpp index fc0d25d0..5dd000f2 100644 --- a/manage/manage.cpp +++ b/manage/manage.cpp @@ -2059,7 +2059,7 @@ int mng_ReplacePage(char *srcname, char *destname, int handle, int dest_pagetype return 0; } // Allocate memory for copying - uint8_t *copybuffer = (uint8_t *)mem_malloc(COPYBUFFER_SIZE); + uint8_t *copybuffer = mem_rmalloc(COPYBUFFER_SIZE); if (!copybuffer) { LOG_ERROR.printf("Couldn't allocate memory to replace page %s!", srcname); cfclose(infile); @@ -2229,7 +2229,7 @@ int mng_DeletePage(char *name, int dest_pagetype, int local) { return 0; } // Allocate memory for copying - uint8_t *copybuffer = (uint8_t *)mem_malloc(COPYBUFFER_SIZE); + uint8_t *copybuffer = mem_rmalloc(COPYBUFFER_SIZE); if (!copybuffer) { LOG_ERROR << "Couldn't allocate memory to delete page!"; cfclose(infile); diff --git a/renderer/HardwareOpenGL.cpp b/renderer/HardwareOpenGL.cpp index 30884159..22956da4 100644 --- a/renderer/HardwareOpenGL.cpp +++ b/renderer/HardwareOpenGL.cpp @@ -273,9 +273,9 @@ int opengl_InitCache() { OpenGL_lightmap_remap = (uint16_t *)mem_malloc(MAX_LIGHTMAPS * 2); ASSERT(OpenGL_lightmap_remap); - OpenGL_bitmap_states = (uint8_t *)mem_malloc(MAX_BITMAPS); + OpenGL_bitmap_states = mem_rmalloc(MAX_BITMAPS); ASSERT(OpenGL_bitmap_states); - OpenGL_lightmap_states = (uint8_t *)mem_malloc(MAX_LIGHTMAPS); + OpenGL_lightmap_states = mem_rmalloc(MAX_LIGHTMAPS); ASSERT(OpenGL_lightmap_states); // Setup textures and cacheing diff --git a/sndlib/ddsoundload.cpp b/sndlib/ddsoundload.cpp index 31d5aa68..20ab4866 100644 --- a/sndlib/ddsoundload.cpp +++ b/sndlib/ddsoundload.cpp @@ -371,7 +371,7 @@ char SoundLoadWaveFile(const char *filename, float percent_volume, int sound_fil SoundFiles[sound_file_index].sample_length = aligned_size; SoundFiles[sound_file_index].np_sample_length = cksize; - SoundFiles[sound_file_index].sample_8bit = (uint8_t *)mem_malloc(aligned_size); + SoundFiles[sound_file_index].sample_8bit = mem_rmalloc(aligned_size); cf_ReadBytes((uint8_t *)SoundFiles[sound_file_index].sample_8bit, cksize, cfptr); @@ -438,7 +438,7 @@ char SoundLoadWaveFile(const char *filename, float percent_volume, int sound_fil } else if (SoundFiles[sound_file_index].sample_8bit == NULL && !f_high_quality) { SoundFiles[sound_file_index].sample_8bit = - (uint8_t *)mem_malloc(SoundFiles[sound_file_index].sample_length); + mem_rmalloc(SoundFiles[sound_file_index].sample_length); // Do the volume clipping with the high quality sound for (count = 0; count < (int)SoundFiles[sound_file_index].sample_length; count++) { diff --git a/sndlib/sdlsound.cpp b/sndlib/sdlsound.cpp index 6ab0c359..4d7f1b17 100644 --- a/sndlib/sdlsound.cpp +++ b/sndlib/sdlsound.cpp @@ -174,7 +174,7 @@ bool lnxsound::SetSoundQuality(char quality) { int count; ASSERT(SoundFiles[j].sample_8bit == nullptr); - SoundFiles[j].sample_8bit = (uint8_t *)mem_malloc(SoundFiles[j].sample_length); + SoundFiles[j].sample_8bit = mem_rmalloc(SoundFiles[j].sample_length); // NOTE: Interesting note on sound conversion: 16 bit sounds are signed (0 biase). 8 bit sounds are unsigned // (+128 biase). diff --git a/stream_audio/streamaudio.cpp b/stream_audio/streamaudio.cpp index e3070bfc..8de53231 100644 --- a/stream_audio/streamaudio.cpp +++ b/stream_audio/streamaudio.cpp @@ -538,7 +538,7 @@ bool AudioStream::ReopenDigitalStream(uint8_t fbufidx, int nbufs) { if (m_buffer[m_fbufidx].data) { mem_free(m_buffer[m_fbufidx].data); } - m_buffer[m_fbufidx].data = (uint8_t *)mem_malloc(m_bufsize); + m_buffer[m_fbufidx].data = mem_rmalloc(m_bufsize); } m_buffer[m_fbufidx].nbytes = AudioStream::ReadFileData(m_fbufidx, m_bufsize); m_buffer[m_fbufidx].flags = 0; @@ -857,7 +857,7 @@ void AudioStream::UpdateData() { if (m_buffer[m_fbufidx].data) { mem_free(m_buffer[m_fbufidx].data); } - m_buffer[m_fbufidx].data = (uint8_t *)mem_malloc(m_bufsize); + m_buffer[m_fbufidx].data = mem_rmalloc(m_bufsize); } m_buffer[m_fbufidx].nbytes = AudioStream::ReadFileData(m_fbufidx, m_bufsize); m_buffer[m_fbufidx].flags = 0;