summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2022-08-11 18:41:14 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2022-08-11 18:51:26 -0700
commit3c54e99864eb6dba0d0cde7fe0a23ed7c1f5875f (patch)
treec00b9f2dc00e8b391052d4a8726d356b0d772e8a
parentbbe78f905da6e36ebe1fe520903c760107b92b78 (diff)
Use memcpy() instead of memmove() when buffers are known not to overlap
Most of these came from a mass bcopy() -> memmove() substitution in 1993 with a commit comment of "ANSIfication". Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--src/Alloc.c2
-rw-r--r--src/Convert.c4
-rw-r--r--src/Create.c6
-rw-r--r--src/Error.c4
-rw-r--r--src/GetResList.c10
-rw-r--r--src/Initialize.c8
-rw-r--r--src/Resources.c10
-rw-r--r--src/Selection.c28
-rw-r--r--src/SetValues.c12
-rw-r--r--src/Shell.c11
-rw-r--r--src/TMkey.c3
-rw-r--r--src/TMparse.c26
12 files changed, 60 insertions, 64 deletions
diff --git a/src/Alloc.c b/src/Alloc.c
index 7271ca9..85b84fd 100644
--- a/src/Alloc.c
+++ b/src/Alloc.c
@@ -389,7 +389,7 @@ _XtRealloc(char *ptr, unsigned size, const char *file, int line)
if (copysize > size)
copysize = size;
- memmove(newptr, ptr, copysize);
+ memcpy(newptr, ptr, copysize);
_XtFree(ptr);
}
UNLOCK_PROCESS;
diff --git a/src/Convert.c b/src/Convert.c
index 17faaa3..7dbeafc 100644
--- a/src/Convert.c
+++ b/src/Convert.c
@@ -403,7 +403,7 @@ CacheEnter(Heap *heap,
else {
p->from_is_value = False;
p->from.addr = (XPointer) _XtHeapAlloc(heap, from->size);
- (void) memmove((char *) p->from.addr, (char *) from->addr, from->size);
+ (void) memcpy(p->from.addr, (char *) from->addr, from->size);
}
p->num_args = (unsigned short) num_args;
if (num_args && args) {
@@ -428,7 +428,7 @@ CacheEnter(Heap *heap,
else {
p->to_is_value = False;
p->to.addr = (XPointer) _XtHeapAlloc(heap, to->size);
- (void) memmove((char *) p->to.addr, (char *) to->addr, to->size);
+ (void) memcpy(p->to.addr, (char *) to->addr, to->size);
}
UNLOCK_PROCESS;
return p;
diff --git a/src/Create.c b/src/Create.c
index 511aa39..2b7fbf2 100644
--- a/src/Create.c
+++ b/src/Create.c
@@ -411,7 +411,7 @@ xtCreate(String name,
wsize = widget_class->core_class.widget_size;
req_widget = (Widget) XtStackAlloc(wsize, widget_cache);
- (void) memmove((char *) req_widget, (char *) widget, (size_t) wsize);
+ (void) memcpy(req_widget, (char *) widget, (size_t) wsize);
CallInitialize(XtClass(widget), req_widget, widget, args, num_args);
if (parent_constraint_class != NULL) {
double constraint_cache[20];
@@ -420,7 +420,7 @@ xtCreate(String name,
csize = parent_constraint_class->constraint_class.constraint_size;
if (csize) {
req_constraints = XtStackAlloc(csize, constraint_cache);
- (void) memmove((char *) req_constraints, widget->core.constraints,
+ (void) memcpy(req_constraints, widget->core.constraints,
(size_t) csize);
req_widget->core.constraints = req_constraints;
}
@@ -782,7 +782,7 @@ _XtCreateHookObj(Screen *screen)
CompileCallbacks(hookobj);
wsize = hookObjectClass->core_class.widget_size;
req_widget = (Widget) XtStackAlloc(wsize, widget_cache);
- (void) memmove((char *) req_widget, (char *) hookobj, (size_t) wsize);
+ (void) memcpy(req_widget, (char *) hookobj, (size_t) wsize);
CallInitialize(hookObjectClass, req_widget, hookobj,
(ArgList) NULL, (Cardinal) 0);
XtStackFree((XtPointer) req_widget, widget_cache);
diff --git a/src/Error.c b/src/Error.c
index ed5990a..93e3c9e 100644
--- a/src/Error.c
+++ b/src/Error.c
@@ -266,7 +266,7 @@ DefaultMsg(String name,
if (i > 10)
i = 10;
- (void) memmove((char *) par, (char *) params, i * sizeof(String));
+ (void) memcpy(par, params, i * sizeof(String));
memset(&par[i], 0, (10 - i) * sizeof(String));
(void) fprintf(stderr, "%s%s",
error ? XTERROR_PREFIX : XTWARNING_PREFIX,
@@ -305,7 +305,7 @@ program as a non-root user or by removing the suid bit on the executable.");
if (i > 10)
i = 10;
- (void) memmove((char *) par, (char *) params, i * sizeof(String));
+ (void) memcpy(par, params, i * sizeof(String));
memset(&par[i], 0, (10 - i) * sizeof(String));
if (i != *num_params)
XtWarning("Some arguments in following message were lost");
diff --git a/src/GetResList.c b/src/GetResList.c
index 817a60c..b0665fe 100644
--- a/src/GetResList.c
+++ b/src/GetResList.c
@@ -96,9 +96,8 @@ XtGetResourceList(WidgetClass widget_class,
if (!widget_class->core_class.class_inited) {
/* Easy case */
- (void) memmove((char *) *resources,
- (char *) widget_class->core_class.resources,
- (size_t) size);
+ (void) memcpy(*resources, widget_class->core_class.resources,
+ (size_t) size);
*num_resources = widget_class->core_class.num_resources;
UNLOCK_PROCESS;
return;
@@ -169,9 +168,8 @@ XtGetConstraintResourceList(WidgetClass widget_class,
if (!class->core_class.class_inited) {
/* Easy case */
- (void) memmove((char *) *resources,
- (char *) class->constraint_class.resources,
- (size_t) size);
+ (void) memcpy(*resources, class->constraint_class.resources,
+ (size_t) size);
*num_resources = class->constraint_class.num_resources;
UNLOCK_PROCESS;
return;
diff --git a/src/Initialize.c b/src/Initialize.c
index 8252d59..d400088 100644
--- a/src/Initialize.c
+++ b/src/Initialize.c
@@ -672,7 +672,7 @@ _MergeOptionTables(const XrmOptionDescRec *src1,
__XtMalloc((Cardinal)
(sizeof(XrmOptionDescRec) * (num_src1 + num_src2)));
- (void) memmove(table, src1, sizeof(XrmOptionDescRec) * num_src1);
+ (void) memcpy(table, src1, sizeof(XrmOptionDescRec) * num_src1);
if (num_src2 == 0) {
*num_dst = num_src1;
return;
@@ -748,7 +748,7 @@ _GetResource(Display *dpy,
if (Qtype == _XtQString)
*(String *) value->addr = db_value.addr;
else
- (void) memmove(value->addr, db_value.addr, value->size);
+ (void) memcpy(value->addr, db_value.addr, value->size);
return True;
}
else {
@@ -788,7 +788,7 @@ _XtPreparseCommandLine(XrmOptionDescRec *urlist,
targv = (_XtString *)
__XtMalloc((Cardinal) (sizeof(_XtString *) * (size_t) argc));
- (void) memmove(targv, argv, sizeof(char *) * (size_t) argc);
+ (void) memcpy(targv, argv, sizeof(char *) * (size_t) argc);
_MergeOptionTables(opTable, XtNumber(opTable), urlist, num_urs,
&options, &num_options);
name_list[0] = class_list[0] = XrmPermStringToQuark(".");
@@ -931,7 +931,7 @@ _XtDisplayInitialize(Display *dpy,
sizeof(XrmHashTable));
if (!(search_list = (XrmHashTable *) ALLOCATE_LOCAL(size)))
_XtAllocError(NULL);
- (void) memmove((char *) search_list, (char *) old, (size >> 1));
+ (void) memcpy(search_list, old, (size >> 1));
DEALLOCATE_LOCAL(old);
}
diff --git a/src/Resources.c b/src/Resources.c
index 3f225dc..d8ea4fc 100644
--- a/src/Resources.c
+++ b/src/Resources.c
@@ -133,7 +133,7 @@ _XtCopyFromArg(XtArgVal src, char *dst, register unsigned int size)
else
p = (char *) &src;
- (void) memmove(dst, p, (size_t) size);
+ (void) memcpy(dst, p, (size_t) size);
}
} /* _XtCopyFromArg */
@@ -157,7 +157,7 @@ _XtCopyToArg(char *src, XtArgVal *dst, register unsigned int size)
} u;
if (size <= sizeof(XtArgVal)) {
- (void) memmove((char *) &u, (char *) src, (size_t) size);
+ (void) memcpy(&u, src, (size_t) size);
if (size == sizeof(long))
*dst = (XtArgVal) u.longval;
#ifdef LONG64
@@ -207,7 +207,7 @@ CopyToArg(char *src, XtArgVal *dst, register unsigned int size)
} u;
if (size <= sizeof(XtArgVal)) {
- (void) memmove((char *) &u, (char *) src, (size_t) size);
+ (void) memcpy(&u, src, (size_t) size);
if (size == sizeof(long))
*dst = (XtArgVal) u.longval;
#ifdef LONG64
@@ -925,8 +925,8 @@ GetResources(Widget widget, /* Widget resources are associated with
__XtMalloc((Cardinal)
(sizeof(XtCacheRef) * (size_t) (cache_ref_size + 1)));
- (void) memmove(refs, cache_ref,
- sizeof(XtCacheRef) * (size_t) cache_ref_size);
+ (void) memcpy(refs, cache_ref,
+ sizeof(XtCacheRef) * (size_t) cache_ref_size);
refs[cache_ref_size] = NULL;
return refs;
}
diff --git a/src/Selection.c b/src/Selection.c
index 9215d05..4f69ae4 100644
--- a/src/Selection.c
+++ b/src/Selection.c
@@ -292,12 +292,12 @@ MakeInfo(Select ctx,
info->callbacks = (XtSelectionCallbackProc *)
__XtMalloc((unsigned)
((size_t) count * sizeof(XtSelectionCallbackProc)));
- (void) memmove((char *) info->callbacks, (char *) callbacks,
- (size_t) count * sizeof(XtSelectionCallbackProc));
+ (void) memcpy(info->callbacks, callbacks,
+ (size_t) count * sizeof(XtSelectionCallbackProc));
info->req_closure = (XtPointer *)
__XtMalloc((unsigned) ((size_t) count * sizeof(XtPointer)));
- (void) memmove((char *) info->req_closure, (char *) closures,
- (size_t) count * sizeof(XtPointer));
+ (void) memcpy(info->req_closure, closures,
+ (size_t) count * sizeof(XtPointer));
if (count == 1 && properties != NULL && properties[0] != None)
info->property = properties[0];
else {
@@ -309,8 +309,8 @@ MakeInfo(Select ctx,
info->time = time;
info->incremental =
(Boolean *) __XtMalloc((Cardinal) ((size_t) count * sizeof(Boolean)));
- (void) memmove((char *) info->incremental, (char *) incremental,
- (size_t) count * sizeof(Boolean));
+ (void) memcpy(info->incremental, incremental,
+ (size_t) count * sizeof(Boolean));
info->current = 0;
info->value = NULL;
return (info);
@@ -1240,7 +1240,7 @@ HandleGetIncrement(Widget widget,
int size = (int) BYTELENGTH(length, info->format) + 1;
char *tmp = __XtMalloc((Cardinal) size);
- (void) memmove(tmp, value, (size_t) size);
+ (void) memcpy(tmp, value, (size_t) size);
XFree(value);
value = tmp;
#endif
@@ -1256,7 +1256,7 @@ HandleGetIncrement(Widget widget,
info->value = XtRealloc(info->value,
(Cardinal) info->bytelength);
}
- (void) memmove(&info->value[info->offset], value, (size_t) size);
+ (void) memcpy(&info->value[info->offset], value, (size_t) size);
info->offset += size;
XFree(value);
}
@@ -1353,7 +1353,7 @@ HandleNormal(Display *dpy,
int size = (int) BYTELENGTH(length, info->format) + 1;
char *tmp = __XtMalloc((Cardinal) size);
- (void) memmove(tmp, value, (size_t) size);
+ (void) memcpy(tmp, value, (size_t) size);
XFree(value);
value = (unsigned char *) tmp;
}
@@ -1514,7 +1514,7 @@ DoLocalTransfer(Request req,
/* both sides think they own this storage */
temp = __XtMalloc((unsigned) bytelength);
- (void) memmove(temp, value, (size_t) bytelength);
+ (void) memcpy(temp, value, (size_t) bytelength);
value = temp;
}
/* use care; older clients were never warned that
@@ -1545,7 +1545,7 @@ DoLocalTransfer(Request req,
(Cardinal) (totallength =
totallength +
(unsigned long) bytelength));
- (void) memmove((char *) total + totallength - bytelength,
+ (void) memcpy((char *) total + totallength - bytelength,
value, (size_t) bytelength);
(*(XtConvertSelectionIncrProc) ctx->convert)
(ctx->widget, &selection, &target,
@@ -1577,7 +1577,7 @@ DoLocalTransfer(Request req,
/* both sides think they own this storage; better copy */
temp = __XtMalloc((unsigned) bytelength);
- (void) memmove(temp, value, (size_t) bytelength);
+ (void) memcpy(temp, value, (size_t) bytelength);
value = temp;
}
if (value == NULL)
@@ -1757,7 +1757,7 @@ GetSelectionValues(Widget widget,
info->target = (Atom *)
__XtMalloc((unsigned) ((size_t) (count + 1) * sizeof(Atom)));
(*info->target) = ctx->prop_list->indirect_atom;
- (void) memmove((char *) info->target + sizeof(Atom), (char *) targets,
+ (void) memcpy((char *) info->target + sizeof(Atom), targets,
(size_t) count * sizeof(Atom));
pairs = (IndirectPair *)
__XtMalloc((unsigned) ((size_t) count * sizeof(IndirectPair)));
@@ -2289,7 +2289,7 @@ XtGetSelectionParameters(Widget owner,
int size = (int) BYTELENGTH(*length_return, *format_return) + 1;
char *tmp = __XtMalloc((Cardinal) size);
- (void) memmove(tmp, *value_return, (size_t) size);
+ (void) memcpy(tmp, *value_return, (size_t) size);
XFree(*value_return);
*value_return = tmp;
}
diff --git a/src/SetValues.c b/src/SetValues.c
index d05fcc5..d24ca03 100644
--- a/src/SetValues.c
+++ b/src/SetValues.c
@@ -224,7 +224,7 @@ XtSetValues(register Widget w, ArgList args, Cardinal num_args)
UNLOCK_PROCESS;
oldw = (Widget) XtStackAlloc(widgetSize, oldwCache);
reqw = (Widget) XtStackAlloc(widgetSize, reqwCache);
- (void) memmove((char *) oldw, (char *) w, (size_t) widgetSize);
+ (void) memcpy(oldw, w, (size_t) widgetSize);
/* Set resource values */
@@ -233,7 +233,7 @@ XtSetValues(register Widget w, ArgList args, Cardinal num_args)
wc->core_class.num_resources, args, num_args);
UNLOCK_PROCESS;
- (void) memmove((char *) reqw, (char *) w, (size_t) widgetSize);
+ (void) memcpy(reqw, w, (size_t) widgetSize);
hasConstraints = (XtParent(w) != NULL && !XtIsShell(w) &&
XtIsConstraint(XtParent(w)));
@@ -257,8 +257,8 @@ XtSetValues(register Widget w, ArgList args, Cardinal num_args)
/* Allocate and copy current constraints into oldw */
oldw->core.constraints = XtStackAlloc(constraintSize, oldcCache);
reqw->core.constraints = XtStackAlloc(constraintSize, reqcCache);
- (void) memmove((char *) oldw->core.constraints,
- (char *) w->core.constraints, (size_t) constraintSize);
+ (void) memcpy(oldw->core.constraints,
+ w->core.constraints, (size_t) constraintSize);
/* Set constraint values */
LOCK_PROCESS;
@@ -266,8 +266,8 @@ XtSetValues(register Widget w, ArgList args, Cardinal num_args)
(XrmResourceList *) (cwc->constraint_class.resources),
cwc->constraint_class.num_resources, args, num_args);
UNLOCK_PROCESS;
- (void) memmove((char *) reqw->core.constraints,
- (char *) w->core.constraints, (size_t) constraintSize);
+ (void) memcpy(reqw->core.constraints,
+ w->core.constraints, (size_t) constraintSize);
}
/* Inform widget of changes, then inform parent of changes */
diff --git a/src/Shell.c b/src/Shell.c
index 07713cc..1e9f338 100644
--- a/src/Shell.c
+++ b/src/Shell.c
@@ -956,10 +956,9 @@ ClassPartInitialize(WidgetClass widget_class)
XtPointer *extP
= &((ShellWidgetClass) widget_class)->shell_class.extension;
ext = XtNew(ShellClassExtensionRec);
- (void) memmove((char *) ext,
- (char *) _FindClassExtension(widget_class->
- core_class.superclass),
- sizeof(ShellClassExtensionRec));
+ (void) memcpy(ext,
+ _FindClassExtension(widget_class->core_class.superclass),
+ sizeof(ShellClassExtensionRec));
ext->next_extension = *extP;
*extP = (XtPointer) ext;
}
@@ -1801,8 +1800,8 @@ GetGeometry(Widget W, Widget child)
WMShellPart *wm = &((WMShellWidget) w)->wm;
EvaluateSizeHints((WMShellWidget) w);
- (void) memmove((char *) &hints, (char *) &wm->size_hints,
- sizeof(struct _OldXSizeHints));
+ (void) memcpy(&hints, &wm->size_hints,
+ sizeof(struct _OldXSizeHints));
hints.win_gravity = wm->win_gravity;
if (wm->size_hints.flags & PBaseSize) {
width -= wm->base_width;
diff --git a/src/TMkey.c b/src/TMkey.c
index b747f07..49b7547 100644
--- a/src/TMkey.c
+++ b/src/TMkey.c
@@ -740,8 +740,7 @@ XtKeysymToKeycodeList(Display *dpy,
maxcodes += KEYCODE_ARRAY_SIZE;
keycodes = (KeyCode *) __XtMalloc(maxcodes * sizeof(KeyCode));
if (ncodes) {
- (void) memmove((char *) keycodes, (char *) old,
- ncodes * sizeof(KeyCode));
+ (void) memcpy(keycodes, old, ncodes * sizeof(KeyCode));
XtFree((char *) old);
}
codeP = &keycodes[ncodes];
diff --git a/src/TMparse.c b/src/TMparse.c
index b20d787..49fc29c 100644
--- a/src/TMparse.c
+++ b/src/TMparse.c
@@ -673,7 +673,7 @@ FetchModifierToken(String str, XrmQuark *token_return)
modStr = XtStackAlloc((size_t) (str - start + 1), modStrbuf);
if (modStr == NULL)
_XtAllocError(NULL);
- (void) memmove(modStr, start, (size_t) (str - start));
+ (void) memcpy(modStr, start, (size_t) (str - start));
modStr[str - start] = '\0';
*token_return = XrmStringToQuark(modStr);
XtStackFree(modStr, modStrbuf);
@@ -784,7 +784,7 @@ ParseXtEventType(register String str,
eventTypeStr = XtStackAlloc((size_t) (str - start + 1), eventTypeStrbuf);
if (eventTypeStr == NULL)
_XtAllocError(NULL);
- (void) memmove(eventTypeStr, start, (size_t) (str - start));
+ (void) memcpy(eventTypeStr, start, (size_t) (str - start));
eventTypeStr[str - start] = '\0';
*tmEventP = LookupTMEventType(eventTypeStr, error);
XtStackFree(eventTypeStr, eventTypeStrbuf);
@@ -1016,7 +1016,7 @@ ParseKeySym(register String str,
&& *str != '\0')
str++;
keySymName = XtStackAlloc((size_t) (str - start + 1), keySymNamebuf);
- (void) memmove(keySymName, start, (size_t) (str - start));
+ (void) memcpy(keySymName, start, (size_t) (str - start));
keySymName[str - start] = '\0';
event->event.eventCode = StringToKeySym(keySymName, error);
event->event.eventCodeMask = (unsigned long) (~0L);
@@ -1062,7 +1062,7 @@ ParseTable(register String str, Opaque closure, EventPtr event, Boolean *error)
*error = TRUE;
return str;
}
- (void) memmove(tableSymName, start, (size_t) (str - start));
+ (void) memcpy(tableSymName, start, (size_t) (str - start));
tableSymName[str - start] = '\0';
signature = StringToQuark(tableSymName);
for (; table->signature != NULLQUARK; table++)
@@ -1105,7 +1105,7 @@ ParseButton(String str, Opaque closure, EventPtr event, Boolean *error)
*error = TRUE;
return PanicModeRecovery(str);
}
- (void) memmove(buttonStr, start, len);
+ (void) memcpy(buttonStr, start, len);
buttonStr[len] = '\0';
button = StrToNum(buttonStr);
if (button < 1 || 255 < button) {
@@ -1154,7 +1154,7 @@ ParseAtom(String str, Opaque closure _X_UNUSED, EventPtr event, Boolean *error)
*error = TRUE;
return str;
}
- (void) memmove(atomName, start, (size_t) (str - start));
+ (void) memcpy(atomName, start, (size_t) (str - start));
atomName[str - start] = '\0';
event->event.eventCode = (TMLongCard) XrmStringToQuark(atomName);
event->event.matchEvent = _XtMatchAtom;
@@ -1566,7 +1566,7 @@ ParseRepeat(register String str, int *reps, Boolean *plus, Boolean *error)
ScanNumeric(str);
len = (size_t) (str - start);
if (len < sizeof repStr) {
- (void) memmove(repStr, start, len);
+ (void) memcpy(repStr, start, len);
repStr[len] = '\0';
*reps = (int) StrToNum(repStr);
}
@@ -1706,7 +1706,7 @@ ParseActionProc(register String str, XrmQuark *actionProcNameP, Boolean *error)
*error = TRUE;
return str;
}
- (void) memmove(procName, start, (size_t) (str - start));
+ (void) memcpy(procName, start, (size_t) (str - start));
procName[str - start] = '\0';
*actionProcNameP = XrmStringToQuark(procName);
return str;
@@ -1734,7 +1734,7 @@ ParseString(register String str, _XtString *strP)
(*(str + 1) == '\\' && *(str + 2) == '"'))) {
len = (unsigned) (prev_len + (str - start + 2));
*strP = XtRealloc(*strP, len);
- (void) memmove(*strP + prev_len, start, (size_t) (str - start));
+ (void) memcpy(*strP + prev_len, start, (size_t) (str - start));
prev_len = len - 1;
str++;
(*strP)[prev_len - 1] = *str;
@@ -1745,7 +1745,7 @@ ParseString(register String str, _XtString *strP)
}
len = (unsigned) (prev_len + (str - start + 1));
*strP = XtRealloc(*strP, len);
- (void) memmove(*strP + prev_len, start, (size_t) (str - start));
+ (void) memcpy(*strP + prev_len, start, (size_t) (str - start));
(*strP)[len - 1] = '\0';
if (*str == '"')
str++;
@@ -1762,7 +1762,7 @@ ParseString(register String str, _XtString *strP)
&& *str != '\0')
str++;
*strP = __XtMalloc((unsigned) (str - start + 1));
- (void) memmove(*strP, start, (size_t) (str - start));
+ (void) memcpy(*strP, start, (size_t) (str - start));
(*strP)[str - start] = '\0';
}
return str;
@@ -1910,7 +1910,7 @@ ShowProduction(String currentProduction)
production = XtStackAlloc(len + 1, productionbuf);
if (production == NULL)
_XtAllocError(NULL);
- (void) memmove(production, currentProduction, len);
+ (void) memcpy(production, currentProduction, len);
production[len] = '\0';
params[0] = production;
@@ -1972,7 +1972,7 @@ CheckForPoundSign(String str,
start = str;
str = ScanIdent(str);
len = MIN(19, (int) (str - start));
- (void) memmove(operation, start, (size_t) len);
+ (void) memcpy(operation, start, (size_t) len);
operation[len] = '\0';
if (!strcmp(operation, "replace"))
opType = XtTableReplace;