diff --git a/src/Composite.c b/src/Composite.c
index 6dfb247c4fb7a6db94b7a689c47bbc02336cf9bd..9708633e6f4728430c933bd32bf50623c56b4394 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 9d140792f08a82428ac4646c61387e0a01d5a802..5570e93e81efed49f80bb896e296fbcee8c92545 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 1fdf35ca0ed4e5203254f5b4f0c8ddf9e941275a..ffe3f8589c6b59d5d8eb7d2f6d188a06e2a7d243 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 6b6a24fe59d2994924976ea1922fb003c5d1ec12..879b71a60d9011b56940ce88b7039f40a3be7f59 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 1bb5bd028ea80ab186f3d323d21a884fd3e3afce..3939a1828d28246fc76652e84f24633ed0fe6939 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 4f76841e7565328ad75c2a1eb8ffc71078538b28..37e441a73ec98956f917be2735ab14c80232583f 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 467ac06fb6a12434ae6ffb864c57080f11bc74cc..091f78e1b7b058ae81a824fcacad9c67feea291b 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 1928a810d1b7c6aacc6f8f4366b3113f1fd43e77..890cad7c157131681ff319199a17eb2fa6503439 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 d53339e93dbb34f46a6e7f9b4cd8da2e826ee72c..274f9d779055d5dd2f201f0ee29c00f86a1a1629 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 f1ebbd7ce9bb715b32192d28fe2993782c4fffc2..618d73bf1f5dc9953019ee2f4695a918bf2e937f 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 9118bb65039225941b71e4d90950f0c8d63270ce..3fbc87909ead61210842852593d61aee22ca5d45 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 2c443c0b9fe15c170c65f12acdc6f1e78e6f4688..40a5c19e7fa6de041888f8068e6afed540e1c882 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 c542ca32ae895d94a1e120d971e07f652fafdb14..2fe7fe59c841eec7cfc40aed95e6c1e1de75238e 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 e4893eb1396d85d26e162d46f147d25e808c12c8..7a5a04d61fa2d0d83c4f6b0cfffd1fe13bf4691b 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 4181ce52b4ea88cb18cdecb956eb492619247cdb..566e71c4aef6e43e94dd64ac12cacbe720ebabb6 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 ecebf3f69665d29174bacad52892140763d227ed..70cd32b670ab9ad3ed4b0fc2a83ba4c135b8b022 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 3da055627ef21b1d1daafd076f2e270ca581a9d4..0e5b5865ccc822d48a403502ec93ce334cbf7743 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--)