mem_malloc type triviality checks (7/8)

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

View File

@ -305,7 +305,7 @@ bool ParseForHotTags(const char *src, char **dest) {
int curr_size = length;
int curr_index = 0;
dest_ptr = *dest = (char *)mem_malloc(length);
dest_ptr = *dest = mem_rmalloc<char>(length);
if (!dest_ptr)
return false;
char replacement[256];

View File

@ -581,7 +581,7 @@ bool Inventory::AddCounterMeasure(int id, int aux_type, int aux_id, int flags, c
if (Weapons[id].icon_handle >= 0) {
newnode->icon_name =
(char *)mem_malloc(strlen(GameBitmaps[GameTextures[Weapons[id].icon_handle].bm_handle].name) + 1);
mem_rmalloc<char>(strlen(GameBitmaps[GameTextures[Weapons[id].icon_handle].bm_handle].name) + 1);
strcpy(newnode->icon_name, GameBitmaps[GameTextures[Weapons[id].icon_handle].bm_handle].name);
} else {
newnode->icon_name = nullptr;
@ -647,7 +647,7 @@ bool Inventory::AddObjectItem(int otype, int oid, int oauxt, int oauxi, int flag
newnode->oid = oauxi;
if (Object_info[oid].description) {
newnode->description = (char *)mem_malloc(strlen(Object_info[oid].description) + 1);
newnode->description = mem_rmalloc<char>(strlen(Object_info[oid].description) + 1);
strcpy(newnode->description, Object_info[oid].description);
} else {
newnode->description = mem_rmalloc<char>();
@ -672,7 +672,7 @@ bool Inventory::AddObjectItem(int otype, int oid, int oauxt, int oauxi, int flag
if (flags & INVAF_LEVELLAST)
newnode->iflags |= INVAF_LEVELLAST;
newnode->icon_name = (char *)mem_malloc(strlen(Object_info[oid].icon_name) + 1);
newnode->icon_name = mem_rmalloc<char>(strlen(Object_info[oid].icon_name) + 1);
strcpy(newnode->icon_name, Object_info[oid].icon_name);
if (description) {

View File

@ -1686,7 +1686,7 @@ int ReadObject(CFILE *ifile, object *objp, int handle, int fileversion) {
// Set the name
if (tempname[0]) {
objp->name = (char *)mem_malloc(strlen(tempname) + 1);
objp->name = mem_rmalloc<char>(strlen(tempname) + 1);
strcpy(objp->name, tempname);
}
@ -2446,7 +2446,7 @@ int ReadRoom(CFILE *ifile, room *rp, int version) {
char tempname[ROOM_NAME_LEN + 1];
cf_ReadString(tempname, sizeof(tempname), ifile);
if (strlen(tempname)) {
rp->name = (char *)mem_malloc(strlen(tempname) + 1);
rp->name = mem_rmalloc<char>(strlen(tempname) + 1);
strcpy(rp->name, tempname);
}
}

View File

@ -1030,13 +1030,13 @@ bool CreateTextStatic(tceffect *tce, const char *text) {
if (!text)
return false;
tce->text_buffer = (char *)mem_malloc(strlen(text) + 10);
tce->text_buffer = mem_rmalloc<char>(strlen(text) + 10);
if (!tce->text_buffer)
return false;
tce->alpha = 255;
char *tempbuffer = (char *)mem_malloc(strlen(text) + 10);
char *tempbuffer = mem_rmalloc<char>(strlen(text) + 10);
if (!tempbuffer)
return false;
strcpy(tempbuffer, text);
@ -1053,11 +1053,11 @@ bool CreateTextFade(tceffect *tce, const char *text) {
ASSERT(text);
if (!text || text[0] == '\0')
return false;
tce->text_buffer = (char *)mem_malloc(strlen(text) + 10);
tce->text_buffer = mem_rmalloc<char>(strlen(text) + 10);
if (!tce->text_buffer)
return false;
char *tempbuffer = (char *)mem_malloc(strlen(text) + 10);
char *tempbuffer = mem_rmalloc<char>(strlen(text) + 10);
if (!tempbuffer)
return false;
strcpy(tempbuffer, text);
@ -1084,11 +1084,11 @@ bool CreateTextType(tceffect *tce, const char *text) {
ASSERT(text);
if (!text || text[0] == '\0')
return false;
tce->text_buffer = (char *)mem_malloc(strlen(text) + 10);
tce->text_buffer = mem_rmalloc<char>(strlen(text) + 10);
if (!tce->text_buffer)
return false;
char *tempbuffer = (char *)mem_malloc(strlen(text) + 10);
char *tempbuffer = mem_rmalloc<char>(strlen(text) + 10);
if (!tempbuffer)
return false;
strcpy(tempbuffer, text);
@ -1252,7 +1252,7 @@ bool CreateMovie(tceffect *tce, const char *filename) {
tce->movieinfo.filename = NULL;
tce->w = tce->h = 100;
tce->movieinfo.filename = (char *)mem_malloc(strlen(filename) + 1);
tce->movieinfo.filename = mem_rmalloc<char>(strlen(filename) + 1);
if (!tce->movieinfo.filename)
return false;
strcpy(tce->movieinfo.filename, filename);

View File

@ -1693,7 +1693,7 @@ void DemoReadPersistantHUDMessage() {
flags = cf_ReadInt(Demo_cfp);
sound_index = cf_ReadInt(Demo_cfp);
int msglen = cf_ReadShort(Demo_cfp);
fmt = (char *)mem_malloc(msglen);
fmt = mem_rmalloc<char>(msglen);
cf_ReadBytes((uint8_t *)fmt, msglen, Demo_cfp);
AddPersistentHUDMessage(color, x, y, time, flags, sound_index, fmt);
mem_free(fmt);

View File

@ -721,7 +721,7 @@ void menutga_LoadHotSpotMap(int back_bmp, const char *filename, hotspotmap_t *hs
// left top
size = ((wndmap->wm[count].l_end_x) - (wndmap->wm[count].l_start_x)) *
((wndmap->wm[count].t_bottom_y) - (wndmap->wm[count].t_top_y));
wndmap->wm[count].lt = (char *)mem_malloc(size);
wndmap->wm[count].lt = mem_rmalloc<char>(size);
for (index = 0; index < size; index++) {
wndmap->wm[count].lt[index] = cf_ReadByte(infile);
}
@ -729,7 +729,7 @@ void menutga_LoadHotSpotMap(int back_bmp, const char *filename, hotspotmap_t *hs
// right top
size = ((wndmap->wm[count].r_end_x) - (wndmap->wm[count].r_start_x)) *
((wndmap->wm[count].t_bottom_y) - (wndmap->wm[count].t_top_y));
wndmap->wm[count].rt = (char *)mem_malloc(size);
wndmap->wm[count].rt = mem_rmalloc<char>(size);
for (index = 0; index < size; index++) {
wndmap->wm[count].rt[index] = cf_ReadByte(infile);
}
@ -739,14 +739,14 @@ void menutga_LoadHotSpotMap(int back_bmp, const char *filename, hotspotmap_t *hs
// left bottom
size = ((wndmap->wm[count].l_end_x) - (wndmap->wm[count].l_start_x)) *
((wndmap->wm[count].b_bottom_y) - (wndmap->wm[count].b_top_y));
wndmap->wm[count].lb = (char *)mem_malloc(size);
wndmap->wm[count].lb = mem_rmalloc<char>(size);
for (index = 0; index < size; index++) {
wndmap->wm[count].lb[index] = cf_ReadByte(infile);
}
// right bottom
size = ((wndmap->wm[count].r_end_x) - (wndmap->wm[count].r_start_x)) *
((wndmap->wm[count].b_bottom_y) - (wndmap->wm[count].b_top_y));
wndmap->wm[count].rb = (char *)mem_malloc(size);
wndmap->wm[count].rb = mem_rmalloc<char>(size);
for (index = 0; index < size; index++) {
wndmap->wm[count].rb[index] = cf_ReadByte(infile);
}
@ -872,7 +872,7 @@ bool menutga_ConvertTGAtoHSM(const char *fpath) {
}
int size = strlen(filename) + 5;
menu_filename = (char *)mem_malloc(size);
menu_filename = mem_rmalloc<char>(size);
strcpy(menu_filename, filename);
strcat(menu_filename, ".HSM"); // Hot Spot Map
LOG_DEBUG.printf("HSM=%s", menu_filename);

View File

@ -840,7 +840,7 @@ void InitHUDItem(int new_item, tHUDItem *item) {
break;
case HUD_ITEM_CUSTOMTEXT2: // malloc buffer to be updated later
HUD_array[new_item].data.text = (char *)mem_malloc(item->buffer_size);
HUD_array[new_item].data.text = mem_rmalloc<char>(item->buffer_size);
HUD_array[new_item].data.text[0] = 0;
HUD_array[new_item].buffer_size = item->buffer_size;
stat = STAT_CUSTOM;
@ -998,7 +998,7 @@ bool LGSHudState(CFILE *fp) {
huditem.render_fn = NULL; // use pointer to function void (*fn)(struct tHUDItem *)
AddHUDItem(&huditem);
buffer = (char *)mem_malloc(huditem.buffer_size);
buffer = mem_rmalloc<char>(huditem.buffer_size);
cf_ReadString(buffer, huditem.buffer_size, fp);
UpdateCustomtext2HUDItem(buffer);
mem_free(buffer);

View File

@ -1628,7 +1628,7 @@ bool MsgListConsole::Open(const char *title, int x, int y, int w, int h) {
m_buflen = 2048;
redo_copy:
m_buffer = (char *)mem_malloc(m_buflen);
m_buffer = mem_rmalloc<char>(m_buflen);
if (m_buffer) {
m_buffer[0] = 0;
m_opened = true;

View File

@ -288,7 +288,7 @@ bool lgoal::SetName(int handle, char *name) {
if (m_name)
mem_free(m_name);
m_name = (char *)mem_malloc(strlen(name) + 1);
m_name = mem_rmalloc<char>(strlen(name) + 1);
strcpy(m_name, name);
m_modified = 1;
@ -320,7 +320,7 @@ bool lgoal::SetCompletionMessage(char *message) {
if (m_completion_message)
mem_free(m_completion_message);
m_completion_message = (char *)mem_malloc(strlen(message) + 1);
m_completion_message = mem_rmalloc<char>(strlen(message) + 1);
strcpy(m_completion_message, message);
return true;
@ -333,7 +333,7 @@ bool lgoal::SetItemName(char *iname) {
if (m_item_name)
mem_free(m_item_name);
m_item_name = (char *)mem_malloc(strlen(iname) + 1);
m_item_name = mem_rmalloc<char>(strlen(iname) + 1);
strcpy(m_item_name, iname);
return true;
@ -442,7 +442,7 @@ bool lgoal::SetDesc(char *desc) {
if (m_desc)
mem_free(m_desc);
m_desc = (char *)mem_malloc(strlen(desc) + 1);
m_desc = mem_rmalloc<char>(strlen(desc) + 1);
strcpy(m_desc, desc);
return true;

View File

@ -667,7 +667,7 @@ void GrowString::operator+=(char *str) {
node = mem_rmalloc<tbufferinfo>();
if (!node)
return;
node->string_data = (char *)mem_malloc(strlen(str) + 2);
node->string_data = mem_rmalloc<char>(strlen(str) + 2);
if (!node->string_data) {
mem_free(node);
return;
@ -677,7 +677,7 @@ void GrowString::operator+=(char *str) {
node->next = NULL;
curr = node;
} else {
root.string_data = (char *)mem_malloc(strlen(str) + 1);
root.string_data = mem_rmalloc<char>(strlen(str) + 1);
if (!root.string_data)
return;
strcpy(root.string_data, str);

View File

@ -725,7 +725,7 @@ void DoMultiAllowed(void) {
bool objsallowed[MAX_OBJECTS];
ConfigItem **ship_list = NULL;
size_t strMax = std::max(strlen(TXT_ALLOW), strlen(TXT_DISALLOW)) + 3;
char *str = (char *)mem_malloc(strMax);
char *str = mem_rmalloc<char>(strMax);
// Create Text Items and Window
UITextItem cancel_on_text(TXT_CANCEL, UICOL_HOTSPOT_HI);

View File

@ -186,7 +186,7 @@ void SubtParseSubtitles(CFILE *file) {
Subtitles[Num_subtitles].first_frame = first_frame;
Subtitles[Num_subtitles].last_frame = last_frame;
Subtitles[Num_subtitles].msg = (char *)mem_malloc(strlen(p) + 1);
Subtitles[Num_subtitles].msg = mem_rmalloc<char>(strlen(p) + 1);
if (!Subtitles[Num_subtitles].msg)
goto subt_parse_error;
strcpy(Subtitles[Num_subtitles].msg, p); // be sure to free this later

View File

@ -503,7 +503,7 @@ int bm_tga_alloc_file(CFILE *infile, char *name, int format) {
cfseek(infile, savepos, SEEK_SET);
Tga_file_data = (char *)mem_malloc(numleft);
Tga_file_data = mem_rmalloc<char>(numleft);
ASSERT(Tga_file_data != NULL);
Fake_pos = 0;
Bad_tga = 0;
@ -661,7 +661,7 @@ int bm_page_in_file(int n) {
cfseek(infile, savepos, SEEK_SET);
Tga_file_data = (char *)mem_malloc(numleft);
Tga_file_data = mem_rmalloc<char>(numleft);
ASSERT(Tga_file_data != NULL);
Fake_pos = 0;
Bad_tga = 0;

View File

@ -239,7 +239,7 @@ int Debug_ErrorBox(int type, const char *title, const char *topstring, const cha
else
debug_break();
char *tmpbuf = (char *)mem_malloc(strlen(topstring) + strlen(bottomstring) + 5);
char *tmpbuf = mem_rmalloc<char>(strlen(topstring) + strlen(bottomstring) + 5);
wsprintf(tmpbuf, "%s\r\n\r\n%s", topstring, bottomstring);
ShowCursor(TRUE);

View File

@ -302,7 +302,7 @@ int ddio_GetFileSysRoots(char **roots, int max_roots) {
while ((count < max_roots) && (!done)) {
if (*strptr != 0) {
strsize = strlen(strptr);
string = roots[count] = (char *)mem_malloc(strsize);
string = roots[count] = mem_rmalloc<char>(strsize);
if (!string)
break;
// remove the trailing \ from windows
@ -336,7 +336,7 @@ std::vector<std::filesystem::path> ddio_GetSysRoots() {
while (!done) {
if (*strptr != 0) {
strsize = strlen(strptr);
string = (char *)mem_malloc(strsize);
string = mem_rmalloc<char>(strsize);
if (!string)
break;
// remove the trailing \ from windows

View File

@ -739,7 +739,7 @@ void BEAddTextEffect(TCTEXTDESC *desc, char *text, char *description, int id) {
mem_free(befx->text);
befx->text = NULL;
}
befx->text = (char *)mem_malloc(strlen(text) + 1);
befx->text = mem_rmalloc<char>(strlen(text) + 1);
ASSERT(befx->text);
strcpy(befx->text, text);
@ -1407,7 +1407,7 @@ void CBriefEdit::OnBriefEffectEdit() {
if (Briefing_screens[scr_index].effects[efx_index].text)
mem_free(Briefing_screens[scr_index].effects[efx_index].text);
Briefing_screens[scr_index].effects[efx_index].text = (char *)mem_malloc(dlg.m_Text.GetLength() + 1);
Briefing_screens[scr_index].effects[efx_index].text = mem_rmalloc<char>(dlg.m_Text.GetLength() + 1);
ASSERT(Briefing_screens[scr_index].effects[efx_index].text);
if (Briefing_screens[scr_index].effects[efx_index].text) {
@ -1651,7 +1651,7 @@ void CBriefEdit::OnBriefEffectText() {
if (Briefing_screens[c_scr].effects[c_eff].text)
mem_free(Briefing_screens[c_scr].effects[c_eff].text);
Briefing_screens[c_scr].effects[c_eff].text = (char *)mem_malloc(dlg.m_Text.GetLength() + 1);
Briefing_screens[c_scr].effects[c_eff].text = mem_rmalloc<char>(dlg.m_Text.GetLength() + 1);
ASSERT(Briefing_screens[c_scr].effects[c_eff].text);
if (Briefing_screens[c_scr].effects[c_eff].text) {

View File

@ -4980,7 +4980,7 @@ int CDallasMainDlg::AddDoorToList(char *name) {
return FALSE;
int pos = m_DoorListSize;
m_DoorList[pos] = (char *)mem_malloc(strlen(name) + 1);
m_DoorList[pos] = mem_rmalloc<char>(strlen(name) + 1);
if (m_DoorList[pos] == NULL) {
MessageBox("Out of memory in AddDoorToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION);
return FALSE;
@ -5018,7 +5018,7 @@ int CDallasMainDlg::AddObjectToList(char *name) {
return FALSE;
int pos = m_ObjectListSize;
m_ObjectList[pos] = (char *)mem_malloc(strlen(name) + 1);
m_ObjectList[pos] = mem_rmalloc<char>(strlen(name) + 1);
if (m_ObjectList[pos] == NULL) {
MessageBox("Out of memory in AddObjectToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION);
return FALSE;
@ -5056,7 +5056,7 @@ int CDallasMainDlg::AddRoomToList(char *name) {
return FALSE;
int pos = m_RoomListSize;
m_RoomList[pos] = (char *)mem_malloc(strlen(name) + 1);
m_RoomList[pos] = mem_rmalloc<char>(strlen(name) + 1);
if (m_RoomList[pos] == NULL) {
MessageBox("Out of memory in AddRoomToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION);
return FALSE;
@ -5094,7 +5094,7 @@ int CDallasMainDlg::AddTriggerToList(char *name) {
return FALSE;
int pos = m_TriggerListSize;
m_TriggerList[pos] = (char *)mem_malloc(strlen(name) + 1);
m_TriggerList[pos] = mem_rmalloc<char>(strlen(name) + 1);
if (m_TriggerList[pos] == NULL) {
MessageBox("Out of memory in AddTriggerToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION);
return FALSE;
@ -5132,7 +5132,7 @@ int CDallasMainDlg::AddSoundToList(char *name) {
return FALSE;
int pos = m_SoundListSize;
m_SoundList[pos] = (char *)mem_malloc(strlen(name) + 1);
m_SoundList[pos] = mem_rmalloc<char>(strlen(name) + 1);
if (m_SoundList[pos] == NULL) {
MessageBox("Out of memory in AddSoundToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION);
return FALSE;
@ -5170,7 +5170,7 @@ int CDallasMainDlg::AddTextureToList(char *name) {
return FALSE;
int pos = m_TextureListSize;
m_TextureList[pos] = (char *)mem_malloc(strlen(name) + 1);
m_TextureList[pos] = mem_rmalloc<char>(strlen(name) + 1);
if (m_TextureList[pos] == NULL) {
MessageBox("Out of memory in AddTextureToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION);
return FALSE;
@ -5208,7 +5208,7 @@ int CDallasMainDlg::AddSpecnameToList(char *name) {
return FALSE;
int pos = m_SpecnameListSize;
m_SpecnameList[pos] = (char *)mem_malloc(strlen(name) + 1);
m_SpecnameList[pos] = mem_rmalloc<char>(strlen(name) + 1);
if (m_SpecnameList[pos] == NULL) {
MessageBox("Out of memory in AddSpecnameToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION);
return FALSE;
@ -5246,7 +5246,7 @@ int CDallasMainDlg::AddPathToList(char *name) {
return FALSE;
int pos = m_PathListSize;
m_PathList[pos] = (char *)mem_malloc(strlen(name) + 1);
m_PathList[pos] = mem_rmalloc<char>(strlen(name) + 1);
if (m_PathList[pos] == NULL) {
MessageBox("Out of memory in AddPathToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION);
return FALSE;
@ -5284,7 +5284,7 @@ int CDallasMainDlg::AddMatcenToList(char *name) {
return FALSE;
int pos = m_MatcenListSize;
m_MatcenList[pos] = (char *)mem_malloc(strlen(name) + 1);
m_MatcenList[pos] = mem_rmalloc<char>(strlen(name) + 1);
if (m_MatcenList[pos] == NULL) {
MessageBox("Out of memory in AddMatcenToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION);
return FALSE;
@ -5322,7 +5322,7 @@ int CDallasMainDlg::AddGoalToList(char *name) {
return FALSE;
int pos = m_GoalListSize;
m_GoalList[pos] = (char *)mem_malloc(strlen(name) + 1);
m_GoalList[pos] = mem_rmalloc<char>(strlen(name) + 1);
if (m_GoalList[pos] == NULL) {
MessageBox("Out of memory in AddGoalToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION);
return FALSE;
@ -5360,7 +5360,7 @@ int CDallasMainDlg::AddStrmAudioToList(char *name) {
return FALSE;
int pos = m_StrmAudioListSize;
m_StrmAudioList[pos] = (char *)mem_malloc(strlen(name) + 1);
m_StrmAudioList[pos] = mem_rmalloc<char>(strlen(name) + 1);
if (m_StrmAudioList[pos] == NULL) {
MessageBox("Out of memory in AddStrmAudioToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION);
return FALSE;
@ -5398,7 +5398,7 @@ int CDallasMainDlg::AddMessageNameToList(char *name) {
return FALSE;
int pos = m_MessageNameListSize;
m_MessageNameList[pos] = (char *)mem_malloc(strlen(name) + 1);
m_MessageNameList[pos] = mem_rmalloc<char>(strlen(name) + 1);
if (m_MessageNameList[pos] == NULL) {
MessageBox("Out of memory in AddMessageNameToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION);
return FALSE;
@ -5512,7 +5512,7 @@ int CDallasMainDlg::AddUserTypeValue(char *utype_name, char *value_name) {
// Store the new value at the current position
tEnumValueEntry *value_entry = &entry->values[j];
value_entry->value = new_value;
value_entry->name = (char *)mem_malloc(strlen(value_name) + 1);
value_entry->name = mem_rmalloc<char>(strlen(value_name) + 1);
if (value_entry->name == NULL) {
MessageBox("ERROR: Out of mem in AddUserTypeValue()!", "Error!");
return (-1);
@ -5582,7 +5582,7 @@ int CDallasMainDlg::ChangeValueName(char *utype_name, char *old_name, char *new_
mem_free(value_entry->name);
// Add the new name
value_entry->name = (char *)mem_malloc(strlen(new_name) + 1);
value_entry->name = mem_rmalloc<char>(strlen(new_name) + 1);
if (value_entry->name == NULL) {
MessageBox("ERROR: Out of mem in ChangeValueName()!", "Error!");
return FALSE;
@ -6185,7 +6185,7 @@ void CDallasMainDlg::ParseFunctionFile(char *filename, bool show_errors /*=TRUE*
done = 1;
else if (m_NumFunctionCategories < MAX_CATEGORIES) {
if (GetFunctionCategoryID(line) == INVALID_CATEGORY) { // don't add duplicate categories
m_FunctionCategories[m_NumFunctionCategories] = (char *)mem_malloc(strlen(line) + 1);
m_FunctionCategories[m_NumFunctionCategories] = mem_rmalloc<char>(strlen(line) + 1);
if (m_FunctionCategories[m_NumFunctionCategories] == NULL) {
FunctionFileParseError(NO_MEM_ERR, linenum, filename);
cfclose(ifile);
@ -6222,7 +6222,7 @@ void CDallasMainDlg::ParseFunctionFile(char *filename, bool show_errors /*=TRUE*
enum_entry = NULL;
} else {
enum_entry = &m_EnumDatabase[m_NumEnums++];
enum_entry->name = (char *)mem_malloc(strlen(enum_name) + 1);
enum_entry->name = mem_rmalloc<char>(strlen(enum_name) + 1);
if (enum_entry->name == NULL) {
FunctionFileParseError(NO_MEM_ERR, linenum, filename);
cfclose(ifile);
@ -6240,7 +6240,7 @@ void CDallasMainDlg::ParseFunctionFile(char *filename, bool show_errors /*=TRUE*
// Add the default (-1:None) value
tEnumValueEntry *value_entry;
value_entry = &enum_entry->values[enum_entry->num_values++];
value_entry->name = (char *)mem_malloc(strlen(USERTYPE_NONE) + 1);
value_entry->name = mem_rmalloc<char>(strlen(USERTYPE_NONE) + 1);
if (value_entry->name == NULL) {
FunctionFileParseError(NO_MEM_ERR, linenum, filename);
cfclose(ifile);
@ -6266,7 +6266,7 @@ void CDallasMainDlg::ParseFunctionFile(char *filename, bool show_errors /*=TRUE*
enum_entry = NULL;
} else {
enum_entry = &m_EnumDatabase[m_NumEnums++];
enum_entry->name = (char *)mem_malloc(strlen(enum_name) + 1);
enum_entry->name = mem_rmalloc<char>(strlen(enum_name) + 1);
if (enum_entry->name == NULL) {
FunctionFileParseError(NO_MEM_ERR, linenum, filename);
cfclose(ifile);
@ -6313,7 +6313,7 @@ void CDallasMainDlg::ParseFunctionFile(char *filename, bool show_errors /*=TRUE*
value_entry = NULL;
} else {
value_entry = &enum_entry->values[enum_entry->num_values++];
value_entry->name = (char *)mem_malloc(strlen(enum_value_name) + 1);
value_entry->name = mem_rmalloc<char>(strlen(enum_value_name) + 1);
if (value_entry->name == NULL) {
FunctionFileParseError(NO_MEM_ERR, linenum, filename);
cfclose(ifile);
@ -6345,7 +6345,7 @@ void CDallasMainDlg::ParseFunctionFile(char *filename, bool show_errors /*=TRUE*
flag_entry = NULL;
} else {
flag_entry = &m_FlagDatabase[m_NumFlags++];
flag_entry->name = (char *)mem_malloc(strlen(flag_name) + 1);
flag_entry->name = mem_rmalloc<char>(strlen(flag_name) + 1);
if (flag_entry->name == NULL) {
FunctionFileParseError(NO_MEM_ERR, linenum, filename);
cfclose(ifile);
@ -6390,7 +6390,7 @@ void CDallasMainDlg::ParseFunctionFile(char *filename, bool show_errors /*=TRUE*
value_entry = NULL;
} else {
value_entry = &flag_entry->values[flag_entry->num_values++];
value_entry->name = (char *)mem_malloc(strlen(flag_value_name) + 1);
value_entry->name = mem_rmalloc<char>(strlen(flag_value_name) + 1);
if (value_entry->name == NULL) {
FunctionFileParseError(NO_MEM_ERR, linenum, filename);
cfclose(ifile);
@ -6439,7 +6439,7 @@ void CDallasMainDlg::ParseFunctionFile(char *filename, bool show_errors /*=TRUE*
RemoveTrailingWhitespace(linebuf);
line = SkipInitialWhitespace(linebuf);
action->desc = (char *)mem_malloc(strlen(line) + 1);
action->desc = mem_rmalloc<char>(strlen(line) + 1);
if (action->desc == NULL) {
FunctionFileParseError(NO_MEM_ERR, linenum, filename);
cfclose(ifile);
@ -6455,7 +6455,7 @@ void CDallasMainDlg::ParseFunctionFile(char *filename, bool show_errors /*=TRUE*
RemoveTrailingWhitespace(linebuf);
line = SkipInitialWhitespace(linebuf);
action->func = (char *)mem_malloc(strlen(line) + 1);
action->func = mem_rmalloc<char>(strlen(line) + 1);
if (action->func == NULL) {
FunctionFileParseError(NO_MEM_ERR, linenum, filename);
cfclose(ifile);
@ -6487,7 +6487,7 @@ void CDallasMainDlg::ParseFunctionFile(char *filename, bool show_errors /*=TRUE*
if (!done)
FunctionFileParseError(UEOF_ERR, linenum, filename);
action->help = (char *)mem_malloc(strlen(helpbuf) + 1);
action->help = mem_rmalloc<char>(strlen(helpbuf) + 1);
if (action->help == NULL) {
FunctionFileParseError(NO_MEM_ERR, linenum, filename);
cfclose(ifile);
@ -6528,7 +6528,7 @@ void CDallasMainDlg::ParseFunctionFile(char *filename, bool show_errors /*=TRUE*
RemoveTrailingWhitespace(linebuf);
line = SkipInitialWhitespace(linebuf);
query->desc = (char *)mem_malloc(strlen(line) + 1);
query->desc = mem_rmalloc<char>(strlen(line) + 1);
if (query->desc == NULL) {
FunctionFileParseError(NO_MEM_ERR, linenum, filename);
cfclose(ifile);
@ -6544,7 +6544,7 @@ void CDallasMainDlg::ParseFunctionFile(char *filename, bool show_errors /*=TRUE*
RemoveTrailingWhitespace(linebuf);
line = SkipInitialWhitespace(linebuf);
query->func = (char *)mem_malloc(strlen(line) + 1);
query->func = mem_rmalloc<char>(strlen(line) + 1);
if (query->func == NULL) {
FunctionFileParseError(NO_MEM_ERR, linenum, filename);
cfclose(ifile);
@ -6576,7 +6576,7 @@ void CDallasMainDlg::ParseFunctionFile(char *filename, bool show_errors /*=TRUE*
if (!done)
FunctionFileParseError(UEOF_ERR, linenum, filename);
query->help = (char *)mem_malloc(strlen(helpbuf) + 1);
query->help = mem_rmalloc<char>(strlen(helpbuf) + 1);
if (query->help == NULL) {
FunctionFileParseError(NO_MEM_ERR, linenum, filename);
cfclose(ifile);
@ -6772,7 +6772,7 @@ bool CDallasMainDlg::ValidateActionNode(HTREEITEM node, int linenum)
child_node=m_ScriptTree.GetChildItem(node);
// Make a copy of description (so null chars can be added)
desc_copy=(char *)mem_malloc(strlen(desc)+1);
desc_copy=mem_rmalloc<char>(strlen(desc)+1);
if(desc_copy==NULL) {
MessageBox("ERROR: Out of memory in ValidateActionNode()!","Out of Memory
Error!",MB_OK|MB_ICONEXCLAMATION); return FALSE;
@ -7047,7 +7047,7 @@ bool CDallasMainDlg::ValidateQueryNode(HTREEITEM node, int linenum)
child_node=m_ScriptTree.GetChildItem(node);
// Make a copy of description (so null chars can be added)
desc_copy=(char *)mem_malloc(strlen(desc)+1);
desc_copy=mem_rmalloc<char>(strlen(desc)+1);
if(desc_copy==NULL) {
MessageBox("ERROR: Out of memory in ValidateQueryNode()!","Out of Memory
Error!",MB_OK|MB_ICONEXCLAMATION); return FALSE;
@ -7137,7 +7137,7 @@ void CDallasMainDlg::FillActionMenu(CMenu *action_menu, int command_offset) {
// Scan the list, adding Actions that match the current category
for (k = 0; k < m_NumActions; k++)
if (m_ActionDatabase[k].category == j) {
char *temp_desc = (char *)mem_malloc(strlen(m_ActionDatabase[k].desc) + 1);
char *temp_desc = mem_rmalloc<char>(strlen(m_ActionDatabase[k].desc) + 1);
if (temp_desc == NULL) {
MessageBox("Out of memory error in FillActionMenu()!", "Memory Error!", MB_OK | MB_ICONEXCLAMATION);
return;
@ -7175,7 +7175,7 @@ void CDallasMainDlg::FillQueryMenu(CMenu *query_menu, int command_offset, int va
// Scan the list, adding queries that match the current category
for (k = 0; k < m_NumActions; k++)
if (m_QueryDatabase[k].category == j) {
char *temp_desc = (char *)mem_malloc(strlen(m_QueryDatabase[k].desc) + 1);
char *temp_desc = mem_rmalloc<char>(strlen(m_QueryDatabase[k].desc) + 1);
if (temp_desc == NULL) {
MessageBox("Out of memory error in FillQueryMenu()!", "Memory Error!", MB_OK | MB_ICONEXCLAMATION);
return;
@ -7848,7 +7848,7 @@ int CDallasMainDlg::ParseSourceScript(char *filename) {
value_entry = NULL;
} else {
value_entry = &enum_entry->values[enum_entry->num_values++];
value_entry->name = (char *)mem_malloc(strlen(enum_value_name) + 1);
value_entry->name = mem_rmalloc<char>(strlen(enum_value_name) + 1);
if (value_entry->name == NULL) {
FunctionFileParseError(NO_MEM_ERR, linenum, filename);
cfclose(infile);
@ -9466,7 +9466,7 @@ int CDallasMainDlg::ParseCustomScriptFile(char *filename, bool show_errors /*=TR
// Store this line
if (m_NumCustomScriptLines < m_MaxNumCustomScriptLines) {
m_CustomScriptLines[m_NumCustomScriptLines] = (char *)mem_malloc(strlen(linebuf) + 1);
m_CustomScriptLines[m_NumCustomScriptLines] = mem_rmalloc<char>(strlen(linebuf) + 1);
if (m_CustomScriptLines[m_NumCustomScriptLines] == NULL) {
MessageBox("ERROR: Ran out of memory parsing custom script block", "Custom Script Parse Error",
MB_OK | MB_ICONEXCLAMATION);
@ -13737,7 +13737,7 @@ void CDallasMainDlg::AddActionParameterNodes(HTREEITEM action_node)
if(desc==NULL) return;
// Make a copy of description (so null chars can be added)
desc_copy=(char *)mem_malloc(strlen(desc)+1);
desc_copy=mem_rmalloc<char>(strlen(desc)+1);
if(desc_copy==NULL) {
MessageBox("ERROR: Out of memory adding action parameter node!","Out of Memory
Error!",MB_OK|MB_ICONEXCLAMATION); return;
@ -13857,7 +13857,7 @@ void CDallasMainDlg::AddQueryParameterNodes(HTREEITEM query_node)
if(desc==NULL) return;
// Make a copy of description (so null chars can be added)
desc_copy=(char *)mem_malloc(strlen(desc)+1);
desc_copy=mem_rmalloc<char>(strlen(desc)+1);
if(desc_copy==NULL) {
MessageBox("ERROR: Out of memory adding query parameter node!","Out of Memory
Error!",MB_OK|MB_ICONEXCLAMATION); return;

View File

@ -282,7 +282,7 @@ inline void CFileList::setPath(CString path) {
if (temp.Right(1) != "\\")
temp += "\\";
buffer = (char *)mem_malloc(temp.GetLength() + 1);
buffer = mem_rmalloc<char>(temp.GetLength() + 1);
if (!buffer)
return;

View File

@ -3171,7 +3171,7 @@ void CMainFrame::OnHotspotTga() {
return;
}
buffer = (char *)mem_malloc(strlen(tga_path.GetBuffer(1)) + 1);
buffer = mem_rmalloc<char>(strlen(tga_path.GetBuffer(1)) + 1);
if (!buffer) {
Int3(); // find Jeff
return;

View File

@ -375,7 +375,7 @@ void CMegacellDialog::OnDeleteMegacell() {
uint16_t texindices[MAX_MEGACELL_WIDTH * MAX_MEGACELL_HEIGHT];
for (i = 0; i < MAX_MEGACELL_WIDTH * MAX_MEGACELL_HEIGHT; i++) {
texnames[i] = (char *)mem_malloc(PAGENAME_LEN);
texnames[i] = mem_rmalloc<char>(PAGENAME_LEN);
ASSERT(texnames[i]);
if (!can_delete[i])
continue;

View File

@ -239,7 +239,7 @@ char *LoadScript(const char *filename) {
cfclose(file);
source = (char *)mem_malloc(strlen(temp.GetBuffer(1)) + 1);
source = mem_rmalloc<char>(strlen(temp.GetBuffer(1)) + 1);
if (!source)
return false;
strcpy(source, temp.GetBuffer(1));
@ -604,7 +604,7 @@ char *AddScriptBlockToScript(char *script, const char *newname, const char *type
sprintf(newhdr, SCRHDR_FORMAT, type_str, newname);
sprintf(newblk, SCRIPT_FORMAT, newname, newhdr);
newsrc = (char *)mem_malloc(strlen(script) + strlen(newblk) + 1);
newsrc = mem_rmalloc<char>(strlen(script) + strlen(newblk) + 1);
if (!newsrc) {
mprintf(1, "Allocation failure in creating new script buffer.\n");
return NULL;
@ -668,7 +668,7 @@ char *AddEventBlockToScript(char *script, const char *evtname, const char *scrip
postblk[postlen] = 0;
sprintf(evtblk, EVT_STATEMENT, evtname);
newtxt = (char *)mem_malloc(strlen(preblk) + strlen(postblk) + strlen(evtblk) + 1);
newtxt = mem_rmalloc<char>(strlen(preblk) + strlen(postblk) + strlen(evtblk) + 1);
sprintf(newtxt, "%s%s%s", preblk, evtblk, postblk);
delete[] postblk;

View File

@ -1160,7 +1160,7 @@ void CObjectDialog::OnObjectSwapButton() {
int o_index = ObjCreate(Object_info[d_id].type, d_id, room, &pos, &orient, parent);
if (temp_name[0] != '\0') {
Objects[o_index].name = (char *)mem_malloc(strlen(temp_name) + 1);
Objects[o_index].name = mem_rmalloc<char>(strlen(temp_name) + 1);
strcpy(Objects[o_index].name, temp_name);
}
}

View File

@ -371,7 +371,7 @@ skip_combine:;
}
ASSERT(rp->name == NULL);
rp->name = (char *)mem_malloc(strlen(roomname) + 1);
rp->name = mem_rmalloc<char>(strlen(roomname) + 1);
strcpy(rp->name, roomname);
// Save it out to disk (locally)

View File

@ -246,7 +246,7 @@ bool CScriptEditorDlg::FindNext(char *w) {
// Make a copy of the script to work with
char *text;
text = (char *)mem_malloc(GetScriptLength());
text = mem_rmalloc<char>(GetScriptLength());
strcpy(text, GetScript());
max = GetScriptLength();

View File

@ -463,7 +463,7 @@ bool CScriptStudio::FindNext(char *w) {
// Make a copy of the script to work with
char *text;
text = (char *)mem_malloc(m_EditText.GetLength() + 1);
text = mem_rmalloc<char>(m_EditText.GetLength() + 1);
if (!text)
Int3();
strcpy(text, (LPCSTR)m_EditText);

View File

@ -317,7 +317,7 @@ void CScriptWizard::OnEditScript() {
FreeScript(m_ScriptSource);
studio.GetText(tempstr);
m_ScriptSource = (char *)mem_malloc(tempstr.GetLength() + 1);
m_ScriptSource = mem_rmalloc<char>(tempstr.GetLength() + 1);
if (m_ScriptSource) {
strcpy(m_ScriptSource, (LPCSTR)tempstr);

View File

@ -393,7 +393,7 @@ void GenericPageList::SaveSelected(CEdit *description) {
// Get Copy of new Description text
description->GetWindowText(new_descrip);
new_text = (char *)mem_malloc(strlen(new_descrip.GetBuffer(0)) + 1);
new_text = mem_rmalloc<char>(strlen(new_descrip.GetBuffer(0)) + 1);
ASSERT(new_text); // out of memory!
sprintf(new_text, "%s", new_descrip.GetBuffer(0));

View File

@ -1548,7 +1548,7 @@ BOOL CTextureGrWnd::OnCommand(WPARAM wParam, LPARAM lParam) {
}
if (strlen(tempname)) {
curobj->name = (char *)mem_malloc(strlen(tempname) + 1);
curobj->name = mem_rmalloc<char>(strlen(tempname) + 1);
strcpy(curobj->name, tempname);
}
@ -1586,14 +1586,14 @@ BOOL CTextureGrWnd::OnCommand(WPARAM wParam, LPARAM lParam) {
if (!dlg.m_Module.IsEmpty()) {
char module_name[MAX_MODULENAME_LEN];
curobj->custom_default_module_name = (char *)mem_malloc(dlg.m_Module.GetLength() + 1);
curobj->custom_default_module_name = mem_rmalloc<char>(dlg.m_Module.GetLength() + 1);
ddio_SplitPath(dlg.m_Module.GetBuffer(0), NULL, module_name, NULL);
strcpy(curobj->custom_default_module_name, module_name);
}
if (!dlg.m_Name.IsEmpty()) {
curobj->custom_default_script_name = (char *)mem_malloc(dlg.m_Name.GetLength() + 1);
curobj->custom_default_script_name = mem_rmalloc<char>(dlg.m_Name.GetLength() + 1);
strcpy(curobj->custom_default_script_name, dlg.m_Name.GetBuffer(0));
}
}

View File

@ -634,7 +634,7 @@ void CWorldObjectsDoorDialog::OnDeleteDoor() {
// Returns true if got new name, false if cancelled.
// the data in buf not changed if cancel is pressed
bool InputDoorName(char *buf, int len, char *title, char *prompt, CWnd *wnd) {
char *tempbuf = (char *)mem_malloc(len);
char *tempbuf = mem_rmalloc<char>(len);
strcpy(tempbuf, buf);

View File

@ -612,7 +612,7 @@ bool InputObjectName(char *buf, int len, char *title, char *prompt, CWnd *wnd) {
if (len > (PAGENAME_LEN - 1))
len = PAGENAME_LEN - 1;
char *tempbuf = (char *)mem_malloc(len);
char *tempbuf = mem_rmalloc<char>(len);
strncpy(tempbuf, buf, len - 1);
tempbuf[len - 1] = '\0';

View File

@ -1102,7 +1102,7 @@ bool InputSoundName(char *buf, int len, char *title, char *prompt, CWnd *wnd) {
if (len > (PAGENAME_LEN - 1))
len = PAGENAME_LEN - 1;
char *tempbuf = (char *)mem_malloc(len);
char *tempbuf = mem_rmalloc<char>(len);
strncpy(tempbuf, buf, len - 1);
tempbuf[len - 1] = '\0';

View File

@ -1998,7 +1998,7 @@ void CWorldTexturesDialog::OnPingPong() {
// Returns true if got new name, false if cancelled.
// the data in buf not changed if cancel is pressed
bool InputTextureName(char *buf, int len, char *title, char *prompt, CWnd *wnd) {
char *tempbuf = (char *)mem_malloc(len);
char *tempbuf = mem_rmalloc<char>(len);
strcpy(tempbuf, buf);

View File

@ -1579,7 +1579,7 @@ void CWorldWeaponsDialog::OnEditPhysics() {
// Returns true if got new name, false if cancelled.
// the data in buf not changed if cancel is pressed
bool InputWeaponName(char *buf, int len, char *title, char *prompt, CWnd *wnd) {
char *tempbuf = (char *)mem_malloc(len);
char *tempbuf = mem_rmalloc<char>(len);
strcpy(tempbuf, buf);

View File

@ -1269,7 +1269,7 @@ try_again:;
}
if (strlen(tempname)) {
Curroomp->name = (char *)mem_malloc(strlen(tempname) + 1);
Curroomp->name = mem_rmalloc<char>(strlen(tempname) + 1);
strcpy(Curroomp->name, tempname);
}

View File

@ -437,7 +437,7 @@ void CRoomKeypadDialog::OnLoadRoom() {
}
ASSERT(Rooms[n].name == NULL);
Rooms[n].name = (char *)mem_malloc(strlen(roomname) + 1);
Rooms[n].name = mem_rmalloc<char>(strlen(roomname) + 1);
strcpy(Rooms[n].name, roomname);
D3EditState.current_room = n;

View File

@ -461,7 +461,7 @@ void grtext_Puts(int x, int y, const char *str) {
if (grtext_FilterProfanity) {
// DAJ changed to local to reduce memory thrashing
// DAJ char *lowerstr = (char *)mem_malloc(strlen(str)+1);
// DAJ char *lowerstr = mem_rmalloc<char>(strlen(str)+1);
char lowerstr[GR_STR_LEN];
int slen = strlen(str);

View File

@ -1144,7 +1144,7 @@ int mng_ReadNewGenericPage(CFILE *infile, mngs_generic_page *genericpage) {
cf_ReadString(tempbuf, 1024, infile);
size_t slen = strlen(tempbuf) + 1;
genericpage->objinfo_struct.description = (char *)mem_malloc(slen);
genericpage->objinfo_struct.description = mem_rmalloc<char>(slen);
ASSERT(genericpage->objinfo_struct.description);
strcpy(genericpage->objinfo_struct.description, tempbuf);
} else

View File

@ -179,7 +179,7 @@ bool OutrageMusicSeq::Init(const char *theme_file) {
// initialize memory buffers
m_ins_buffer = mem_rmalloc<music_ins>(MAX_MUSIC_INSTRUCTIONS);
m_str_buffer = (char *)mem_malloc(MAX_MUSIC_STRLEN);
m_str_buffer = mem_rmalloc<char>(MAX_MUSIC_STRLEN);
m_ins_curptr = m_ins_buffer;
m_str_curptr = m_str_buffer;
m_str_curptr[0] = 0;

View File

@ -110,7 +110,7 @@ void UIConsoleGadget::Create(UIWindow *parent, int id, int x, int y, int font, i
// extra 32 bytes per row for color coding.
m_ConsoleBuffer = (char *)mem_malloc(m_Rows * m_Rowsize);
m_PutsBufLen = 512;
m_PutsBuffer = (char *)mem_malloc(m_PutsBufLen);
m_PutsBuffer = mem_rmalloc<char>(m_PutsBufLen);
m_ColorRows = new ddgr_color[m_Rows];
memset(m_ConsoleBuffer, 0, m_Rows * m_Rowsize);
@ -141,7 +141,7 @@ void UIConsoleGadget::puts(ddgr_color col, const char *str) {
if (len >= m_PutsBufLen) {
mem_free(m_PutsBuffer);
m_PutsBufLen = len + 1;
m_PutsBuffer = (char *)mem_malloc(m_PutsBufLen);
m_PutsBuffer = mem_rmalloc<char>(m_PutsBufLen);
}
textaux_WordWrap(str, m_PutsBuffer, m_W - 2 * m_OffX, m_ConsoleFont);