mem_malloc type triviality checks (6/8)

```
git grep -l mem_malloc | xargs perl -i -lpe 's{\((uint8_t) \*\)mem_malloc\((\S+)\)}{mem_rmalloc<$1>($2)}'
```
This commit is contained in:
Jan Engelhardt 2024-08-30 20:54:35 +02:00
parent 1551b240d3
commit de0af3b10d
16 changed files with 32 additions and 32 deletions

View File

@ -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<uint8_t>(bytesize);
ft->char_data = mem_rmalloc<uint8_t *>(num_char);
READ_FONT_DATA(ff, ft->raw_data, bytesize, 1);

View File

@ -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<uint8_t>(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<int16_t *>(Rooms[i].num_bbf_regions);
Rooms[i].bbf_list_min_xyz = mem_rmalloc<vector>(Rooms[i].num_bbf_regions);
Rooms[i].bbf_list_max_xyz = mem_rmalloc<vector>(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<uint8_t>(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<uint8_t>(MAX_LIGHTMAPS);
uint8_t *free_lightmap_info = mem_rmalloc<uint8_t>(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<uint16_t>(MAX_LIGHTMAPS);
uint8_t *lightmap_spoken_for = (uint8_t *)mem_malloc(MAX_LIGHTMAPS);
uint8_t *lightmap_spoken_for = mem_rmalloc<uint8_t>(MAX_LIGHTMAPS);
ASSERT(lightmap_remap);
ASSERT(lightmap_spoken_for);

View File

@ -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<uint8_t>(Rooms[i].num_faces);
ASSERT(Small_faces[i]);
memset(Small_faces[i], 0, Rooms[i].num_faces);

View File

@ -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<uint8_t>(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<uint8_t>(aligned_size);
cf_ReadBytes((uint8_t *)wave->sample_8bit, cksize, cfptr);

View File

@ -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<uint8_t>(size);
Room_mem_size = size;
Room_mem_ptr = Room_mem_buf;

View File

@ -823,7 +823,7 @@ int LoadPCXTerrain(char *filename) {
total = width * height;
lando = (uint8_t *)mem_malloc(total);
lando = mem_rmalloc<uint8_t>(total);
LOG_DEBUG.printf("Heightmap is %d x %d", width, height);

View File

@ -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<uint8_t>(256);
ASSERT(touch_buffer[i]);
memset(touch_buffer[i], 255, 256);
}

View File

@ -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<uint8_t>(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<uint8_t>(Rooms[i].num_faces);
ASSERT(RoomsAlreadyCombined[i]);
for (k = 0; k < Rooms[i].num_faces; k++)
RoomsAlreadyCombined[i][k] = 0;

View File

@ -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<uint8_t>(sm->num_faces);
ASSERT(ObjectsAlreadyCombined[i]);
for (k = 0; k < sm->num_faces; k++)
ObjectsAlreadyCombined[i][k] = 0;

View File

@ -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<uint8_t>(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<uint8_t>(bytesize);
fnt.char_data = mem_rmalloc<uint8_t *>(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<uint8_t>(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<uint8_t>(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<uint8_t>(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<uint8_t>(bytesize);
READ_FONT_DATA(ffin, fnt.raw_data, bytesize, 1);

View File

@ -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<uint8_t>(MAX_BITMAPS);
ASSERT(OpenGL_bitmap_states);
OpenGL_lightmap_states = (uint8_t *)mem_malloc(MAX_LIGHTMAPS);
OpenGL_lightmap_states = mem_rmalloc<uint8_t>(MAX_LIGHTMAPS);
ASSERT(OpenGL_lightmap_states);
Cur_texture_object_num = 1;

View File

@ -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<uint8_t>(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<uint8_t>(COPYBUFFER_SIZE);
if (!copybuffer) {
LOG_ERROR << "Couldn't allocate memory to delete page!";
cfclose(infile);

View File

@ -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<uint8_t>(MAX_BITMAPS);
ASSERT(OpenGL_bitmap_states);
OpenGL_lightmap_states = (uint8_t *)mem_malloc(MAX_LIGHTMAPS);
OpenGL_lightmap_states = mem_rmalloc<uint8_t>(MAX_LIGHTMAPS);
ASSERT(OpenGL_lightmap_states);
// Setup textures and cacheing

View File

@ -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<uint8_t>(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<uint8_t>(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++) {

View File

@ -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<uint8_t>(SoundFiles[j].sample_length);
// NOTE: Interesting note on sound conversion: 16 bit sounds are signed (0 biase). 8 bit sounds are unsigned
// (+128 biase).

View File

@ -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<uint8_t>(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<uint8_t>(m_bufsize);
}
m_buffer[m_fbufidx].nbytes = AudioStream::ReadFileData(m_fbufidx, m_bufsize);
m_buffer[m_fbufidx].flags = 0;