summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Wiederhake <twied@gmx.net>2023-12-30 20:49:48 +0100
committerTim Wiederhake <twied@gmx.net>2024-01-21 13:14:37 +0100
commit365a94b62df6144ad016e587f3756d974b6e2018 (patch)
tree08182cf099e612ba7830c929375c56c06035368a
parent7fe0acdb259c7dd9f3b6214ba16f272da81beadb (diff)
Add explicit cast after memory allocation
Still valid c, but now also valid c++. Signed-off-by: Tim Wiederhake <twied@gmx.net>
-rw-r--r--src/add_window.c20
-rw-r--r--src/iconmgr.c4
-rw-r--r--src/icons.c8
-rw-r--r--src/list.c2
-rw-r--r--src/menus.c16
-rw-r--r--src/parse.c6
-rw-r--r--src/session.c11
-rw-r--r--src/twm.c8
-rw-r--r--src/util.c7
9 files changed, 44 insertions, 38 deletions
diff --git a/src/add_window.c b/src/add_window.c
index 009d8f8..3caf15b 100644
--- a/src/add_window.c
+++ b/src/add_window.c
@@ -171,7 +171,7 @@ AddWindow(Window w, int iconm, IconMgr *iconp)
#endif
/* allocate space for the twm window */
- tmp_win = calloc(1, sizeof(TwmWindow));
+ tmp_win = (TwmWindow *) calloc(1, sizeof(TwmWindow));
if (tmp_win == NULL) {
twmWarning("Unable to allocate memory to manage window ID %lx.", w);
return NULL;
@@ -359,7 +359,7 @@ AddWindow(Window w, int iconm, IconMgr *iconp)
if (LookInList(Scr->StartIconified, tmp_win->full_name, &tmp_win->xclass)) {
if (!tmp_win->wmhints) {
- tmp_win->wmhints = malloc(sizeof(XWMHints));
+ tmp_win->wmhints = (XWMHints *) malloc(sizeof(XWMHints));
tmp_win->wmhints->flags = 0;
}
tmp_win->wmhints->initial_state = IconicState;
@@ -1304,7 +1304,8 @@ CreateWindowTitlebarButtons(TwmWindow *tmp_win)
tmp_win->titlebuttons = NULL;
nb = Scr->TBInfo.nleft + Scr->TBInfo.nright;
if (nb > 0) {
- tmp_win->titlebuttons = malloc((size_t) nb * sizeof(TBWindow));
+ tmp_win->titlebuttons = (TBWindow *)
+ malloc((size_t) nb * sizeof(TBWindow));
if (!tmp_win->titlebuttons) {
twmWarning("unable to allocate %d titlebuttons", nb);
}
@@ -1395,7 +1396,7 @@ CreateTwmColormap(Colormap c)
{
TwmColormap *cmap;
- cmap = calloc(1, sizeof(TwmColormap));
+ cmap = (TwmColormap *) calloc(1, sizeof(TwmColormap));
if (!cmap || XSaveContext(dpy, c, ColormapContext, (XPointer) cmap)) {
if (cmap)
free(cmap);
@@ -1416,7 +1417,7 @@ CreateColormapWindow(Window w, Bool creating_parent, Bool property_window)
TwmColormap *cmap;
XWindowAttributes attributes;
- cwin = malloc(sizeof(ColormapWindow));
+ cwin = (ColormapWindow *) malloc(sizeof(ColormapWindow));
if (cwin) {
if (!XGetWindowAttributes(dpy, w, &attributes) ||
XSaveContext(dpy, w, ColormapContext, (XPointer) cwin)) {
@@ -1497,7 +1498,7 @@ FetchWmColormapWindows(TwmWindow *tmp)
break;
}
if (i == number_cmap_windows) { /* not in list */
- Window *new_cmap_windows =
+ Window *new_cmap_windows = (Window *)
malloc(sizeof(Window) * (size_t) (number_cmap_windows + 1));
if (!new_cmap_windows) {
@@ -1516,7 +1517,8 @@ FetchWmColormapWindows(TwmWindow *tmp)
number_cmap_windows++;
}
- cwins = malloc(sizeof(ColormapWindow *) * (size_t) number_cmap_windows);
+ cwins = (ColormapWindow **)
+ malloc(sizeof(ColormapWindow *) * (size_t) number_cmap_windows);
if (cwins) {
for (i = 0; i < number_cmap_windows; i++) {
@@ -1565,7 +1567,7 @@ FetchWmColormapWindows(TwmWindow *tmp)
number_cmap_windows = 1;
- cwins = malloc(sizeof(ColormapWindow *));
+ cwins = (ColormapWindow **) malloc(sizeof(ColormapWindow *));
if (XFindContext(dpy, tmp->w, ColormapContext, (XPointer *) &cwins[0])
== XCNOENT) {
cwins[0] =
@@ -1585,7 +1587,7 @@ FetchWmColormapWindows(TwmWindow *tmp)
tmp->cmaps.cwins = cwins;
tmp->cmaps.number_cwins = number_cmap_windows;
if (number_cmap_windows > 1)
- tmp->cmaps.scoreboard =
+ tmp->cmaps.scoreboard = (char *)
calloc(1, ColormapsScoreboardLength(&tmp->cmaps));
if (previously_installed)
diff --git a/src/iconmgr.c b/src/iconmgr.c
index 87749b7..5af92ad 100644
--- a/src/iconmgr.c
+++ b/src/iconmgr.c
@@ -133,7 +133,7 @@ AllocateIconManager(char *name, char *icon_name, char *geom, int columns)
if (Scr->NoIconManagers)
return NULL;
- p = malloc(sizeof(IconMgr));
+ p = (IconMgr *) malloc(sizeof(IconMgr));
p->name = name;
p->icon_name = icon_name;
p->geometry = geom;
@@ -370,7 +370,7 @@ AddIconManager(TwmWindow *tmp_win)
&tmp_win->xclass)) == NULL)
ip = &Scr->iconmgr;
- tmp = malloc(sizeof(WList));
+ tmp = (WList *) malloc(sizeof(WList));
tmp->iconmgr = ip;
tmp->next = NULL;
tmp->active = FALSE;
diff --git a/src/icons.c b/src/icons.c
index 47ff670..3ebb4b2 100644
--- a/src/icons.c
+++ b/src/icons.c
@@ -58,7 +58,7 @@ splitEntry(IconEntry *ie, int grav1, int grav2, int w, int h)
if (w != ie->w)
splitEntry(ie, grav2, grav1, w, ie->h);
if (h != ie->h) {
- entry = malloc(sizeof(IconEntry));
+ entry = (IconEntry *) malloc(sizeof(IconEntry));
entry->twm_win = 0;
entry->used = 0;
entry->next = ie->next;
@@ -80,7 +80,7 @@ splitEntry(IconEntry *ie, int grav1, int grav2, int w, int h)
if (h != ie->h)
splitEntry(ie, grav2, grav1, ie->w, h);
if (w != ie->w) {
- entry = malloc(sizeof(IconEntry));
+ entry = (IconEntry *) malloc(sizeof(IconEntry));
entry->twm_win = 0;
entry->used = 0;
entry->next = ie->next;
@@ -275,7 +275,7 @@ AddIconRegion(char *geom, int grav1, int grav2, int stepx, int stepy)
IconRegion *ir;
int mask;
- ir = malloc(sizeof(IconRegion));
+ ir = (IconRegion *) malloc(sizeof(IconRegion));
ir->next = NULL;
if (Scr->LastRegion)
Scr->LastRegion->next = ir;
@@ -303,7 +303,7 @@ AddIconRegion(char *geom, int grav1, int grav2, int stepx, int stepy)
if (mask & YNegative)
ir->y += Scr->MyDisplayHeight - ir->h;
- ir->entries = malloc(sizeof(IconEntry));
+ ir->entries = (IconEntry *) malloc(sizeof(IconEntry));
ir->entries->next = 0;
ir->entries->x = ir->x;
ir->entries->y = ir->y;
diff --git a/src/list.c b/src/list.c
index f7fa724..cceba24 100644
--- a/src/list.c
+++ b/src/list.c
@@ -90,7 +90,7 @@ AddToList(name_list ** list_head, char *name, char *ptr)
if (!list_head)
return; /* ignore empty inserts */
- nptr = malloc(sizeof(name_list));
+ nptr = (name_list *) malloc(sizeof(name_list));
if (nptr == NULL) {
parseWarning("unable to allocate %lu bytes for name_list",
(unsigned long) sizeof(name_list));
diff --git a/src/menus.c b/src/menus.c
index 39d6d34..44e0904 100644
--- a/src/menus.c
+++ b/src/menus.c
@@ -194,7 +194,7 @@ AddFuncKey(char *name, int cont, int mods2, int func, char *win_name,
}
if (tmp == NULL) {
- tmp = malloc(sizeof(FuncKey));
+ tmp = (FuncKey *) malloc(sizeof(FuncKey));
tmp->next = Scr->FuncKeyRoot.next;
Scr->FuncKeyRoot.next = tmp;
}
@@ -215,7 +215,7 @@ int
CreateTitleButton(const char *name, int func, const char *action,
MenuRoot *menuroot, Bool rightside, Bool append)
{
- TitleButton *tb = malloc(sizeof(TitleButton));
+ TitleButton *tb = (TitleButton *) malloc(sizeof(TitleButton));
if (!tb) {
twmWarning("unable to allocate %lu bytes for title button",
@@ -606,7 +606,7 @@ NewMenuRoot(const char *name)
#define UNUSED_PIXEL ((unsigned long) (~0)) /* more than 24 bits */
- tmp = malloc(sizeof(MenuRoot));
+ tmp = (MenuRoot *) malloc(sizeof(MenuRoot));
tmp->hi_fore = UNUSED_PIXEL;
tmp->hi_back = UNUSED_PIXEL;
tmp->name = name;
@@ -665,7 +665,7 @@ AddToMenu(MenuRoot *menu, const char *item, const char *action,
item, action ? action : "<null>", sub, func);
#endif
- tmp = malloc(sizeof(MenuItem));
+ tmp = (MenuItem *) malloc(sizeof(MenuItem));
tmp->root = menu;
if (menu->first == NULL) {
@@ -955,7 +955,7 @@ PopUpMenu(MenuRoot *menu, int x, int y, Bool center)
if (WindowNameCount != 0) {
int i;
- WindowNames =
+ WindowNames = (TwmWindow **)
malloc(sizeof(TwmWindow *) * (size_t) WindowNameCount);
WindowNames[0] = Scr->TwmRoot.next;
@@ -2309,7 +2309,7 @@ Execute(const char *s)
colon = strrchr(ds, ':');
if (colon) { /* if host[:]:dpy */
size_t need = sizeof(display_eqls) + strlen(ds) + 10;
- char *update = malloc(need);
+ char *update = (char *) malloc(need);
if (update != NULL) {
char *dot1;
@@ -2333,7 +2333,7 @@ Execute(const char *s)
if (restorevar) {
size_t need = sizeof(display_eqls) + strlen(oldDisplay);
- char *update = malloc(need);
+ char *update = (char *) malloc(need);
if (update != NULL) {
(void) snprintf(update, need, "%s%s", display_eqls, oldDisplay);
@@ -2685,7 +2685,7 @@ BumpWindowColormap(TwmWindow *tmp, int inc)
return;
if (inc && tmp->cmaps.number_cwins > 0) {
- cwins =
+ cwins = (ColormapWindow **)
malloc(sizeof(ColormapWindow *) * (size_t) tmp->cmaps.number_cwins);
if (cwins) {
int i;
diff --git a/src/parse.c b/src/parse.c
index 0ad806e..4ffc4aa 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -1037,7 +1037,7 @@ do_var_savecolor(int key)
Cptr cptrav, cpnew;
if (!chead) {
- chead = malloc(sizeof(Cnode));
+ chead = (Cnode *) malloc(sizeof(Cnode));
chead->i = key;
chead->next = NULL;
}
@@ -1046,7 +1046,7 @@ do_var_savecolor(int key)
while (cptrav->next != NULL) {
cptrav = cptrav->next;
}
- cpnew = malloc(sizeof(Cnode));
+ cpnew = (Cnode *) malloc(sizeof(Cnode));
cpnew->i = key;
cpnew->next = NULL;
cptrav->next = cpnew;
@@ -1155,7 +1155,7 @@ do_squeeze_entry(name_list ** list, char *name, int justify, int num, int denom)
if (HasShape) {
SqueezeInfo *sinfo;
- sinfo = malloc(sizeof(SqueezeInfo));
+ sinfo = (SqueezeInfo *) malloc(sizeof(SqueezeInfo));
if (!sinfo) {
parseWarning("unable to allocate %lu bytes for squeeze info",
diff --git a/src/session.c b/src/session.c
index 77e0d3a..92b25bb 100644
--- a/src/session.c
+++ b/src/session.c
@@ -216,7 +216,7 @@ read_counted_string(FILE *file, char **stringp)
data = 0;
}
else {
- data = malloc((unsigned) len + 1);
+ data = (char *) malloc((unsigned) len + 1);
if (!data)
return 0;
if (fread(data, (int) sizeof(char), (int) len, file) != len) {
@@ -368,7 +368,7 @@ ReadWinConfigEntry(FILE *configFile, unsigned short version,
unsigned char byte;
int i;
- *pentry = entry = malloc(sizeof(TWMWinConfigEntry));
+ *pentry = entry = (TWMWinConfigEntry *) malloc(sizeof(TWMWinConfigEntry));
if (!*pentry)
return 0;
@@ -402,8 +402,8 @@ ReadWinConfigEntry(FILE *configFile, unsigned short version,
if (entry->wm_command_count == 0)
entry->wm_command = NULL;
else {
- entry->wm_command = malloc((size_t) entry->wm_command_count *
- sizeof(char *));
+ entry->wm_command = (char **)
+ malloc((size_t) entry->wm_command_count * sizeof(char *));
if (!entry->wm_command)
goto give_up;
@@ -773,7 +773,8 @@ SaveYourselfPhase2CB(SmcConn smcConn2, SmPointer clientData _X_UNUSED)
prop1.name = strdup(SmRestartCommand);
prop1.type = strdup(SmLISTofARRAY8);
- prop1.vals = malloc((size_t) (Argc + 4) * sizeof(SmPropValue));
+ prop1.vals = (SmPropValue *)
+ malloc((size_t) (Argc + 4) * sizeof(SmPropValue));
if (!prop1.vals) {
success = False;
diff --git a/src/twm.c b/src/twm.c
index 1c1e522..78a425c 100644
--- a/src/twm.c
+++ b/src/twm.c
@@ -359,7 +359,8 @@ main(int argc, char *argv[])
InfoLines = 0;
/* for simplicity, always allocate NumScreens ScreenInfo struct pointers */
- ScreenList = calloc((size_t) NumScreens, sizeof(ScreenInfo *));
+ ScreenList = (ScreenInfo **)
+ calloc((size_t) NumScreens, sizeof(ScreenInfo *));
if (ScreenList == NULL) {
twmError("Unable to allocate memory for screen list, exiting");
}
@@ -394,7 +395,7 @@ main(int argc, char *argv[])
numManaged++;
/* Note: ScreenInfo struct is calloc'ed to initialize to zero. */
- Scr = ScreenList[scrnum] = calloc(1, sizeof(ScreenInfo));
+ Scr = ScreenList[scrnum] = (ScreenInfo *) calloc(1, sizeof(ScreenInfo));
if (Scr == NULL) {
twmWarning
("unable to allocate memory for ScreenInfo structure for screen %d.",
@@ -442,7 +443,8 @@ main(int argc, char *argv[])
XSaveContext(dpy, Scr->Root, ScreenContext, (XPointer) Scr);
Scr->TwmRoot.cmaps.number_cwins = 1;
- Scr->TwmRoot.cmaps.cwins = malloc(sizeof(ColormapWindow *));
+ Scr->TwmRoot.cmaps.cwins = (ColormapWindow **)
+ malloc(sizeof(ColormapWindow *));
Scr->TwmRoot.cmaps.cwins[0] =
CreateColormapWindow(Scr->Root, True, False);
Scr->TwmRoot.cmaps.cwins[0]->visibility = VisibilityPartiallyObscured;
diff --git a/src/util.c b/src/util.c
index baff6c8..5671fad 100644
--- a/src/util.c
+++ b/src/util.c
@@ -259,7 +259,7 @@ ExpandFilename(const char *name)
if (name[0] != '~')
return strdup(name);
- newname = malloc((size_t) HomeLen + strlen(name) + 2);
+ newname = (char *) malloc((size_t) HomeLen + strlen(name) + 2);
if (!newname) {
twmWarning("unable to allocate %lu bytes to expand filename %s/%s",
(unsigned long) HomeLen + (unsigned long) strlen(name) + 2,
@@ -358,7 +358,8 @@ FindBitmap(const char *name, unsigned *widthp, unsigned *heightp)
/*
* Attempt to find icon in old IconDirectory (now obsolete)
*/
- bigname = malloc(strlen(name) + strlen(Scr->IconDirectory) + 2);
+ bigname = (char *)
+ malloc(strlen(name) + strlen(Scr->IconDirectory) + 2);
if (!bigname) {
twmWarning("unable to allocate memory for \"%s/%s\"",
Scr->IconDirectory, name);
@@ -399,7 +400,7 @@ InsertRGBColormap(Atom a, XStandardColormap *maps, int nmaps, Bool replace)
}
if (!sc) { /* no existing, allocate new */
- sc = malloc(sizeof(StdCmap));
+ sc = (StdCmap *) malloc(sizeof(StdCmap));
if (!sc) {
twmWarning("unable to allocate %lu bytes for StdCmap",
(unsigned long) sizeof(StdCmap));