summaryrefslogtreecommitdiff
path: root/src/TMstate.c
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2023-03-03 17:42:47 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2023-03-07 00:06:24 +0000
commitb3b0c1ad25a5d0f628eddd00113a40364d68480b (patch)
tree7b1088ab3cc984dd606df1b56fdda7dec975432f /src/TMstate.c
parentb1b54c50d0e5851d72c1e7aff4057687be2e447e (diff)
Replace XtMalloc() calls with XtMallocArray()
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'src/TMstate.c')
-rw-r--r--src/TMstate.c71
1 files changed, 34 insertions, 37 deletions
diff --git a/src/TMstate.c b/src/TMstate.c
index 7a5a04d..8dbf054 100644
--- a/src/TMstate.c
+++ b/src/TMstate.c
@@ -123,20 +123,20 @@ GetBranchHead(TMParseStateTree parseTree,
}
}
if (parseTree->numBranchHeads == parseTree->branchHeadTblSize) {
- TMShortCard newSize;
if (parseTree->branchHeadTblSize == 0)
parseTree->branchHeadTblSize = TM_BRANCH_HEAD_TBL_ALLOC;
else
parseTree->branchHeadTblSize += TM_BRANCH_HEAD_TBL_REALLOC;
- newSize =
- (TMShortCard) (parseTree->branchHeadTblSize *
- sizeof(TMBranchHeadRec));
+
if (parseTree->isStackBranchHeads) {
TMBranchHead oldBranchHeadTbl = parseTree->branchHeadTbl;
- parseTree->branchHeadTbl = (TMBranchHead) __XtMalloc(newSize);
- memcpy(parseTree->branchHeadTbl, oldBranchHeadTbl, newSize);
+ parseTree->branchHeadTbl =
+ XtMallocArray((Cardinal) parseTree->branchHeadTblSize,
+ (Cardinal) sizeof(TMBranchHeadRec));
+ memcpy(parseTree->branchHeadTbl, oldBranchHeadTbl,
+ parseTree->branchHeadTblSize * sizeof(TMBranchHeadRec));
parseTree->isStackBranchHeads = False;
}
else {
@@ -174,20 +174,20 @@ _XtGetQuarkIndex(TMParseStateTree parseTree, XrmQuark quark)
if (i == parseTree->numQuarks) {
if (parseTree->numQuarks == parseTree->quarkTblSize) {
- TMShortCard newSize;
if (parseTree->quarkTblSize == 0)
parseTree->quarkTblSize = TM_QUARK_TBL_ALLOC;
else
parseTree->quarkTblSize += TM_QUARK_TBL_REALLOC;
- newSize =
- (TMShortCard) (parseTree->quarkTblSize * sizeof(XrmQuark));
if (parseTree->isStackQuarks) {
XrmQuark *oldquarkTbl = parseTree->quarkTbl;
- parseTree->quarkTbl = (XrmQuark *) __XtMalloc(newSize);
- memcpy(parseTree->quarkTbl, oldquarkTbl, newSize);
+ parseTree->quarkTbl =
+ XtMallocArray((Cardinal) parseTree->quarkTblSize,
+ (Cardinal) sizeof(XrmQuark));
+ memcpy(parseTree->quarkTbl, oldquarkTbl,
+ parseTree->quarkTblSize * sizeof(XrmQuark));
parseTree->isStackQuarks = False;
}
else {
@@ -215,8 +215,6 @@ GetComplexBranchIndex(TMParseStateTree parseTree,
#define TM_COMPLEXBRANCH_HEAD_TBL_REALLOC 4
if (parseTree->numComplexBranchHeads == parseTree->complexBranchHeadTblSize) {
- TMShortCard newSize;
-
if (parseTree->complexBranchHeadTblSize == 0)
parseTree->complexBranchHeadTblSize =
(TMShortCard) (parseTree->complexBranchHeadTblSize +
@@ -226,16 +224,14 @@ GetComplexBranchIndex(TMParseStateTree parseTree,
(TMShortCard) (parseTree->complexBranchHeadTblSize +
TM_COMPLEXBRANCH_HEAD_TBL_REALLOC);
- newSize =
- (TMShortCard) (parseTree->complexBranchHeadTblSize *
- sizeof(StatePtr));
-
if (parseTree->isStackComplexBranchHeads) {
StatePtr *oldcomplexBranchHeadTbl = parseTree->complexBranchHeadTbl;
- parseTree->complexBranchHeadTbl = (StatePtr *) __XtMalloc(newSize);
- memcpy(parseTree->complexBranchHeadTbl,
- oldcomplexBranchHeadTbl, newSize);
+ parseTree->complexBranchHeadTbl =
+ XtMallocArray((Cardinal) parseTree->complexBranchHeadTblSize,
+ (Cardinal) sizeof(StatePtr));
+ memcpy(parseTree->complexBranchHeadTbl, oldcomplexBranchHeadTbl,
+ parseTree->complexBranchHeadTblSize * sizeof(StatePtr));
parseTree->isStackComplexBranchHeads = False;
}
else {
@@ -285,8 +281,8 @@ _XtGetTypeIndex(Event *event)
(Cardinal) sizeof(TMTypeMatch));
}
_XtGlobalTM.typeMatchSegmentTbl[_XtGlobalTM.numTypeMatchSegments++] =
- segment = (TMTypeMatch)
- __XtMalloc(TM_TYPE_SEGMENT_SIZE * sizeof(TMTypeMatchRec));
+ segment = XtMallocArray(TM_TYPE_SEGMENT_SIZE,
+ (Cardinal) sizeof(TMTypeMatchRec));
j = 0;
}
typeMatch = &segment[j];
@@ -387,8 +383,8 @@ _XtGetModifierIndex(Event *event)
(Cardinal) sizeof(TMModifierMatch));
}
_XtGlobalTM.modMatchSegmentTbl[_XtGlobalTM.numModMatchSegments++] =
- segment = (TMModifierMatch)
- __XtMalloc(TM_MOD_SEGMENT_SIZE * sizeof(TMModifierMatchRec));
+ segment = XtMallocArray(TM_MOD_SEGMENT_SIZE,
+ (Cardinal) sizeof(TMModifierMatchRec));
j = 0;
}
modMatch = &segment[j];
@@ -1402,19 +1398,18 @@ TMStateTree
_XtParseTreeToStateTree(TMParseStateTree parseTree)
{
TMSimpleStateTree simpleTree;
- unsigned int tableSize;
if (parseTree->numComplexBranchHeads) {
TMComplexStateTree complexTree;
complexTree = XtNew(TMComplexStateTreeRec);
complexTree->isSimple = False;
- tableSize =
- (unsigned) (parseTree->numComplexBranchHeads * sizeof(StatePtr));
- complexTree->complexBranchHeadTbl = (StatePtr *)
- __XtMalloc(tableSize);
+ complexTree->complexBranchHeadTbl =
+ XtMallocArray((Cardinal) parseTree->numComplexBranchHeads,
+ (Cardinal) sizeof(StatePtr));
memcpy(complexTree->complexBranchHeadTbl,
- parseTree->complexBranchHeadTbl, tableSize);
+ parseTree->complexBranchHeadTbl,
+ parseTree->numComplexBranchHeads * sizeof(StatePtr));
complexTree->numComplexBranchHeads = parseTree->numComplexBranchHeads;
simpleTree = (TMSimpleStateTree) complexTree;
}
@@ -1426,15 +1421,17 @@ _XtParseTreeToStateTree(TMParseStateTree parseTree)
simpleTree->refCount = 0;
simpleTree->mappingNotifyInterest = parseTree->mappingNotifyInterest;
- tableSize =
- (unsigned) (parseTree->numBranchHeads * sizeof(TMBranchHeadRec));
- simpleTree->branchHeadTbl = (TMBranchHead) __XtMalloc(tableSize);
- memcpy(simpleTree->branchHeadTbl, parseTree->branchHeadTbl, tableSize);
+ simpleTree->branchHeadTbl =
+ XtMallocArray((Cardinal) parseTree->numBranchHeads,
+ (Cardinal) sizeof(TMBranchHeadRec));
+ memcpy(simpleTree->branchHeadTbl, parseTree->branchHeadTbl,
+ parseTree->numBranchHeads * sizeof(TMBranchHeadRec));
simpleTree->numBranchHeads = parseTree->numBranchHeads;
- tableSize = (unsigned) (parseTree->numQuarks * sizeof(XrmQuark));
- simpleTree->quarkTbl = (XrmQuark *) __XtMalloc(tableSize);
- memcpy(simpleTree->quarkTbl, parseTree->quarkTbl, tableSize);
+ simpleTree->quarkTbl = XtMallocArray((Cardinal) parseTree->numQuarks,
+ (Cardinal) sizeof(XrmQuark));
+ memcpy(simpleTree->quarkTbl, parseTree->quarkTbl,
+ parseTree->numQuarks * sizeof(XrmQuark));
simpleTree->numQuarks = parseTree->numQuarks;
return (TMStateTree) simpleTree;