From b1b54c50d0e5851d72c1e7aff4057687be2e447e Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 3 Mar 2023 16:23:20 -0800 Subject: Replace XtRealloc() calls with XtReallocArray() Signed-off-by: Alan Coopersmith --- src/Composite.c | 6 ++---- src/Create.c | 8 +++----- src/Destroy.c | 8 +++----- src/Display.c | 20 +++++++++----------- src/Event.c | 7 +++---- src/EventUtil.c | 5 ++--- src/Hooks.c | 7 +++---- src/NextEvent.c | 13 ++++--------- src/Resources.c | 7 +++---- src/Selection.c | 24 +++++++++--------------- src/TMaction.c | 8 ++++---- src/TMkey.c | 7 ++++--- src/TMparse.c | 6 ++---- src/TMstate.c | 42 +++++++++++++++++++++--------------------- src/Threads.c | 6 +++--- src/VarCreate.c | 5 ++--- src/Varargs.c | 6 ++---- 17 files changed, 79 insertions(+), 106 deletions(-) diff --git a/src/Composite.c b/src/Composite.c index 6dfb247..9708633 100644 --- a/src/Composite.c +++ b/src/Composite.c @@ -247,10 +247,8 @@ CompositeInsertChild(Widget w) /* Allocate more space */ cw->composite.num_slots += (cw->composite.num_slots / 2) + 2; cw->composite.children = children = - (WidgetList) XtRealloc((XtPointer) children, - (Cardinal) ((unsigned) - (cw->composite.num_slots) * - sizeof(Widget))); + XtReallocArray(children, cw->composite.num_slots, + (Cardinal) sizeof(Widget)); } /* Ripple children up one space from "position" */ for (i = cw->composite.num_children; i > position; i--) { diff --git a/src/Create.c b/src/Create.c index 9d14079..5570e93 100644 --- a/src/Create.c +++ b/src/Create.c @@ -629,11 +629,9 @@ popupPostProc(Widget w) { Widget parent = XtParent(w); - parent->core.popup_list = - (WidgetList) XtRealloc((char *) parent->core.popup_list, - (Cardinal) ((unsigned) - (parent->core.num_popups + - 1) * sizeof(Widget))); + parent->core.popup_list = XtReallocArray(parent->core.popup_list, + (parent->core.num_popups + 1), + (Cardinal) sizeof(Widget)); parent->core.popup_list[parent->core.num_popups++] = w; } diff --git a/src/Destroy.c b/src/Destroy.c index 1fdf35c..ffe3f85 100644 --- a/src/Destroy.c +++ b/src/Destroy.c @@ -371,11 +371,9 @@ XtDestroyWidget(Widget widget) if (app->destroy_count == app->destroy_list_size) { app->destroy_list_size += 10; - app->destroy_list = (DestroyRec *) - XtRealloc((char *) app->destroy_list, - (Cardinal) (sizeof(DestroyRec) * - (size_t) app->destroy_list_size) - ); + app->destroy_list = XtReallocArray(app->destroy_list, + (Cardinal) app->destroy_list_size, + (Cardinal) sizeof(DestroyRec)); } dr = app->destroy_list + app->destroy_count++; dr->dispatch_level = app->dispatch_level; diff --git a/src/Display.c b/src/Display.c index 6b6a24f..879b71a 100644 --- a/src/Display.c +++ b/src/Display.c @@ -121,9 +121,9 @@ AddToAppContext(Display *d, XtAppContext app) if (app->count >= app->max) { app->max = (short) (app->max + DISPLAYS_TO_ADD); - app->list = (Display **) XtRealloc((char *) app->list, - (Cardinal) (((size_t) app->max) * - sizeof(Display *))); + app->list = XtReallocArray(app->list, + (Cardinal) app->max, + (Cardinal) sizeof(Display *)); } app->list[app->count++] = d; @@ -550,10 +550,9 @@ XtDestroyApplicationContext(XtAppContext app) app->being_destroyed = TRUE; LOCK_PROCESS; _XtAppDestroyCount++; - appDestroyList = - (XtAppContext *) XtRealloc((char *) appDestroyList, - (unsigned) ((size_t) _XtAppDestroyCount * - sizeof(XtAppContext))); + appDestroyList = XtReallocArray(appDestroyList, + (Cardinal) _XtAppDestroyCount, + (Cardinal) sizeof(XtAppContext)); appDestroyList[_XtAppDestroyCount - 1] = app; UNLOCK_PROCESS; UNLOCK_APP(app); @@ -739,10 +738,9 @@ XtCloseDisplay(Display *dpy) else { pd->being_destroyed = TRUE; app->dpy_destroy_count++; - app->dpy_destroy_list = (Display **) - XtRealloc((char *) app->dpy_destroy_list, - (Cardinal) ((size_t) app->dpy_destroy_count * - sizeof(Display *))); + app->dpy_destroy_list = XtReallocArray(app->dpy_destroy_list, + (Cardinal) app->dpy_destroy_count, + (Cardinal) sizeof(Display *)); app->dpy_destroy_list[app->dpy_destroy_count - 1] = dpy; } UNLOCK_APP(app); diff --git a/src/Event.c b/src/Event.c index 1bb5bd0..3939a18 100644 --- a/src/Event.c +++ b/src/Event.c @@ -1780,10 +1780,9 @@ XtRegisterExtensionSelector(Display *dpy, } } pd->ext_select_count++; - pd->ext_select_list = - (ExtSelectRec *) XtRealloc((char *) pd->ext_select_list, - (Cardinal) ((size_t) pd->ext_select_count * - sizeof(ExtSelectRec))); + pd->ext_select_list = XtReallocArray(pd->ext_select_list, + (Cardinal) pd->ext_select_count, + (Cardinal) sizeof(ExtSelectRec)); for (i = pd->ext_select_count - 1; i > 0; i--) { if (pd->ext_select_list[i - 1].min > min_event_type) { pd->ext_select_list[i] = pd->ext_select_list[i - 1]; diff --git a/src/EventUtil.c b/src/EventUtil.c index 4f76841..37e441a 100644 --- a/src/EventUtil.c +++ b/src/EventUtil.c @@ -160,9 +160,8 @@ _XtFillAncestorList(Widget **listPtr, /* This should rarely happen, but if it does it'll probably happen again, so grow the ancestor list */ *maxElemsPtr += CACHESIZE; - trace = (Widget *) XtRealloc((char *) trace, - (Cardinal) (sizeof(Widget) * - (size_t) (*maxElemsPtr))); + trace = XtReallocArray(trace, (Cardinal) *maxElemsPtr, + (Cardinal) sizeof(Widget)); } trace[i] = w; } diff --git a/src/Hooks.c b/src/Hooks.c index 467ac06..091f78e 100644 --- a/src/Hooks.c +++ b/src/Hooks.c @@ -117,10 +117,9 @@ _XtAddShellToHookObj(Widget shell) if (ho->hooks.num_shells == ho->hooks.max_shells) { ho->hooks.max_shells += SHELL_INCR; - ho->hooks.shells = - (WidgetList) XtRealloc((char *) ho->hooks.shells, - (Cardinal) (ho->hooks.max_shells * - sizeof(Widget))); + ho->hooks.shells = XtReallocArray(ho->hooks.shells, + (Cardinal) ho->hooks.max_shells, + (Cardinal) sizeof(Widget)); } ho->hooks.shells[ho->hooks.num_shells++] = shell; diff --git a/src/NextEvent.c b/src/NextEvent.c index 1928a81..890cad7 100644 --- a/src/NextEvent.c +++ b/src/NextEvent.c @@ -280,10 +280,8 @@ InitFds(XtAppContext app, wf->stack); } else { - wf->fdlist = (struct pollfd *) - XtRealloc((char *) wf->fdlist, - (Cardinal) (sizeof(struct pollfd) * - (size_t) wf->fdlistlen)); + wf->fdlist = XtReallocArray(wf->fdlist, (Cardinal) wf->fdlistlen, + (Cardinal) sizeof(struct pollfd)); } if (wf->fdlistlen) { @@ -1043,11 +1041,8 @@ XtAppAddInput(XtAppContext app, Cardinal n = (Cardinal) (source + 1); int ii; - app->input_list = (InputEvent **) XtRealloc((char *) app->input_list, - (Cardinal) ((size_t) n * - sizeof - (InputEvent - *))); + app->input_list = XtReallocArray(app->input_list, n, + (Cardinal) sizeof(InputEvent *)); for (ii = app->input_max; ii < (int) n; ii++) app->input_list[ii] = (InputEvent *) NULL; app->input_max = (short) n; diff --git a/src/Resources.c b/src/Resources.c index d53339e..274f9d7 100644 --- a/src/Resources.c +++ b/src/Resources.c @@ -596,10 +596,9 @@ GetResources(Widget widget, /* Widget resources are associated with searchList, (int) searchListSize)) { if (searchList == stackSearchList) searchList = NULL; - searchList = (XrmHashTable *) XtRealloc((char *) searchList, - (Cardinal) (sizeof(XrmHashTable) - * (searchListSize *= - 2))); + searchListSize *= 2; + searchList = XtReallocArray(searchList, searchListSize, + (Cardinal) sizeof(XrmHashTable)); } if (persistent_resources) diff --git a/src/Selection.c b/src/Selection.c index f1ebbd7..618d73b 100644 --- a/src/Selection.c +++ b/src/Selection.c @@ -229,11 +229,8 @@ GetSelectionProperty(Display *dpy) } } propCount = sarray->propCount++; - sarray->list = (SelectionProp) XtRealloc((XtPointer) sarray->list, - (Cardinal) ((size_t) sarray-> - propCount * - sizeof - (SelectionPropRec))); + sarray->list = XtReallocArray(sarray->list, (Cardinal) sarray->propCount, + (Cardinal) sizeof(SelectionPropRec)); (void) snprintf(propname, sizeof(propname), "_XT_SELECTION_%d", propCount); sarray->list[propCount].prop = XInternAtom(dpy, propname, FALSE); sarray->list[propCount].avail = FALSE; @@ -1959,9 +1956,8 @@ AddSelectionRequests(Widget wid, int j = 0; qi->count += count; - req = (QueuedRequest *) XtRealloc((char *) req, - (Cardinal) ((size_t) (start + count) * - sizeof(QueuedRequest))); + req = XtReallocArray(req, (Cardinal) (start + count), + (Cardinal) sizeof(QueuedRequest)); while (i < count) { QueuedRequest newreq = (QueuedRequest) __XtMalloc(sizeof(QueuedRequestRec)); @@ -2075,7 +2071,7 @@ XtCreateSelectionRequest(Widget widget, Atom selection) QueuedRequestInfo queueInfo; Window window = XtWindow(widget); Display *dpy = XtDisplay(widget); - int n; + Cardinal n; LOCK_PROCESS; if (multipleContext == 0) @@ -2102,9 +2098,8 @@ XtCreateSelectionRequest(Widget widget, Atom selection) n = 0; while (queueInfo->selections[n] != None) n++; - queueInfo->selections = - (Atom *) XtRealloc((char *) queueInfo->selections, - (Cardinal) ((size_t) (n + 2) * sizeof(Atom))); + queueInfo->selections = XtReallocArray(queueInfo->selections, (n + 2), + (Cardinal) sizeof(Atom)); queueInfo->selections[n] = selection; queueInfo->selections[n + 1] = None; @@ -2332,9 +2327,8 @@ AddParamInfo(Widget w, Atom selection, Atom param_atom) } if (n == 0) { pinfo->count++; - pinfo->paramlist = (Param) - XtRealloc((char *) pinfo->paramlist, - (Cardinal) (pinfo->count * sizeof(ParamRec))); + pinfo->paramlist = XtReallocArray(pinfo->paramlist, pinfo->count, + (Cardinal) sizeof(ParamRec)); p = &pinfo->paramlist[pinfo->count - 1]; (void) XSaveContext(XtDisplay(w), XtWindow(w), paramPropertyContext, (char *) pinfo); diff --git a/src/TMaction.c b/src/TMaction.c index 9118bb6..3fbc879 100644 --- a/src/TMaction.c +++ b/src/TMaction.c @@ -464,10 +464,10 @@ EnterBindCache(Widget w, if (_XtGlobalTM.numBindCache == _XtGlobalTM.bindCacheTblSize) { _XtGlobalTM.bindCacheTblSize = (TMShortCard) (_XtGlobalTM.bindCacheTblSize + 16); - _XtGlobalTM.bindCacheTbl = (TMBindCache *) - XtRealloc((char *) _XtGlobalTM.bindCacheTbl, - (Cardinal) ((_XtGlobalTM.bindCacheTblSize) * - sizeof(TMBindCache))); + _XtGlobalTM.bindCacheTbl = + XtReallocArray(_XtGlobalTM.bindCacheTbl, + (Cardinal) _XtGlobalTM.bindCacheTblSize, + (Cardinal) sizeof(TMBindCache)); } _XtGlobalTM.bindCacheTbl[_XtGlobalTM.numBindCache++] = bindCache; #endif /* TRACE_TM */ diff --git a/src/TMkey.c b/src/TMkey.c index 2c443c0..40a5c19 100644 --- a/src/TMkey.c +++ b/src/TMkey.c @@ -502,9 +502,10 @@ _XtBuildKeysymTables(Display *dpy, register XtPerDisplay pd) if (keysym != 0 && keysym != tempKeysym) { if (tempCount == maxCount) { maxCount += KeysymTableSize; - pd->modKeysyms = (KeySym *) XtRealloc((char *) pd-> - modKeysyms, - (unsigned) ((size_t) maxCount * sizeof(KeySym))); + pd->modKeysyms = + XtReallocArray(pd->modKeysyms, + (Cardinal) maxCount, + (Cardinal) sizeof(KeySym)); } pd->modKeysyms[tempCount++] = keysym; table[i].count++; diff --git a/src/TMparse.c b/src/TMparse.c index c542ca3..2fe7fe5 100644 --- a/src/TMparse.c +++ b/src/TMparse.c @@ -553,10 +553,8 @@ StoreLateBindings(KeySym keysymL, pair = TRUE; } - temp = (LateBindingsPtr) XtRealloc((char *) temp, - (unsigned) ((count + number + - 1) * - sizeof(LateBindings))); + temp = XtReallocArray(temp, (Cardinal) (count + number + 1), + (Cardinal) sizeof(LateBindings)); *lateBindings = temp; XtSetBit(temp[count].knot, notL); XtSetBit(temp[count].pair, pair); diff --git a/src/TMstate.c b/src/TMstate.c index e4893eb..7a5a04d 100644 --- a/src/TMstate.c +++ b/src/TMstate.c @@ -141,9 +141,9 @@ GetBranchHead(TMParseStateTree parseTree, } else { parseTree->branchHeadTbl = (TMBranchHead) - XtRealloc((char *) parseTree->branchHeadTbl, - (Cardinal) (parseTree->branchHeadTblSize * - sizeof(TMBranchHeadRec))); + XtReallocArray(parseTree->branchHeadTbl, + (Cardinal) parseTree->branchHeadTblSize, + (Cardinal) sizeof(TMBranchHeadRec)); } } #ifdef TRACE_TM @@ -192,9 +192,9 @@ _XtGetQuarkIndex(TMParseStateTree parseTree, XrmQuark quark) } else { parseTree->quarkTbl = (XrmQuark *) - XtRealloc((char *) parseTree->quarkTbl, - (Cardinal) (parseTree->quarkTblSize * - sizeof(XrmQuark))); + XtReallocArray(parseTree->quarkTbl, + (Cardinal) parseTree->quarkTblSize, + (Cardinal) sizeof(XrmQuark)); } } parseTree->quarkTbl[parseTree->numQuarks++] = quark; @@ -240,9 +240,9 @@ GetComplexBranchIndex(TMParseStateTree parseTree, } else { parseTree->complexBranchHeadTbl = (StatePtr *) - XtRealloc((char *) parseTree->complexBranchHeadTbl, - (Cardinal) (parseTree->complexBranchHeadTblSize * - sizeof(StatePtr))); + XtReallocArray(parseTree->complexBranchHeadTbl, + (Cardinal) parseTree->complexBranchHeadTblSize, + (Cardinal) sizeof(StatePtr)); } } parseTree->complexBranchHeadTbl[parseTree->numComplexBranchHeads++] = NULL; @@ -280,9 +280,9 @@ _XtGetTypeIndex(Event *event) _XtGlobalTM.typeMatchSegmentTblSize = (TMShortCard) (_XtGlobalTM.typeMatchSegmentTblSize + 4); _XtGlobalTM.typeMatchSegmentTbl = (TMTypeMatch *) - XtRealloc((char *) _XtGlobalTM.typeMatchSegmentTbl, - (Cardinal) (_XtGlobalTM.typeMatchSegmentTblSize * - sizeof(TMTypeMatch))); + XtReallocArray(_XtGlobalTM.typeMatchSegmentTbl, + (Cardinal) _XtGlobalTM.typeMatchSegmentTblSize, + (Cardinal) sizeof(TMTypeMatch)); } _XtGlobalTM.typeMatchSegmentTbl[_XtGlobalTM.numTypeMatchSegments++] = segment = (TMTypeMatch) @@ -382,9 +382,9 @@ _XtGetModifierIndex(Event *event) _XtGlobalTM.modMatchSegmentTblSize = (TMShortCard) (_XtGlobalTM.modMatchSegmentTblSize + 4); _XtGlobalTM.modMatchSegmentTbl = (TMModifierMatch *) - XtRealloc((char *) _XtGlobalTM.modMatchSegmentTbl, - (Cardinal) (_XtGlobalTM.modMatchSegmentTblSize * - sizeof(TMModifierMatch))); + XtReallocArray(_XtGlobalTM.modMatchSegmentTbl, + (Cardinal) _XtGlobalTM.modMatchSegmentTblSize, + (Cardinal) sizeof(TMModifierMatch)); } _XtGlobalTM.modMatchSegmentTbl[_XtGlobalTM.numModMatchSegments++] = segment = (TMModifierMatch) @@ -712,9 +712,9 @@ PushContext(TMContext *contextPtr, StatePtr newState) (TMShortCard) (context->maxMatches + TM_CONTEXT_MATCHES_REALLOC); context->matches = (MatchPairRec *) - XtRealloc((char *) context->matches, - (Cardinal) (context->maxMatches * - sizeof(MatchPairRec))); + XtReallocArray(context->matches, + (Cardinal) context->maxMatches, + sizeof(MatchPairRec)); } context->matches[context->numMatches].isCycleStart = newState->isCycleStart; @@ -1376,9 +1376,9 @@ _XtCreateXlations(TMStateTree *stateTrees, if (_XtGlobalTM.numTms == _XtGlobalTM.tmTblSize) { _XtGlobalTM.tmTblSize = (TMShortCard) (_XtGlobalTM.tmTblSize + 16); _XtGlobalTM.tmTbl = (XtTranslations *) - XtRealloc((char *) _XtGlobalTM.tmTbl, - (Cardinal) (_XtGlobalTM.tmTblSize * - sizeof(XtTranslations))); + XtReallocArray(_XtGlobalTM.tmTbl, + (Cardinal) _XtGlobalTM.tmTblSize, + (Cardinal) sizeof(XtTranslations)); } _XtGlobalTM.tmTbl[_XtGlobalTM.numTms++] = xlations; UNLOCK_PROCESS; diff --git a/src/Threads.c b/src/Threads.c index 4181ce5..566e71c 100644 --- a/src/Threads.c +++ b/src/Threads.c @@ -239,9 +239,9 @@ YieldAppLock(XtAppContext app, unsigned ii; app_lock->stack.st = (struct _Tstack *) - XtRealloc((char *) app_lock->stack.st, - (Cardinal) ((app_lock->stack.size + - STACK_INCR) * sizeof(struct _Tstack))); + XtReallocArray(app_lock->stack.st, + (Cardinal) (app_lock->stack.size + STACK_INCR), + (Cardinal) sizeof(struct _Tstack)); ii = app_lock->stack.size; app_lock->stack.size += STACK_INCR; for (; ii < app_lock->stack.size; ii++) { diff --git a/src/VarCreate.c b/src/VarCreate.c index ecebf3f..70cd32b 100644 --- a/src/VarCreate.c +++ b/src/VarCreate.c @@ -295,9 +295,8 @@ _XtVaOpenApplication(XtAppContext *app_context_return, typed_args[count].size = 0; } count++; - typed_args = (XtTypedArgList) - XtRealloc((char *) typed_args, - (Cardinal) ((size_t) (count + 1) * sizeof(XtTypedArg))); + typed_args = XtReallocArray(typed_args, (Cardinal) count + 1, + (Cardinal) sizeof(XtTypedArg)); } typed_args[count].name = NULL; diff --git a/src/Varargs.c b/src/Varargs.c index 3da0556..0e5b586 100644 --- a/src/Varargs.c +++ b/src/Varargs.c @@ -428,10 +428,8 @@ GetResources(Widget widget, XtResourceList *res_list, Cardinal *number) &num_constraint); cons_top = constraint; - *res_list = (XtResourceList) XtRealloc((char *) *res_list, - (Cardinal) ((*number + - num_constraint) * - sizeof(XtResource))); + *res_list = XtReallocArray(*res_list, *number + num_constraint, + (Cardinal) sizeof(XtResource)); for (temp = num_constraint, res = *res_list + *number; temp != 0; temp--) -- cgit v1.2.3