mirror of https://gitee.com/openkylin/libvirt.git
src: Use virStrcpyStatic() wherever possible
This convenience macro was created for the simple cases where the length of the source string and the size of the destination buffer can be figued out with strlen() and sizeof() respectively, so we should use it wherever possible instead of open-coding parts of it. Signed-off-by: Andrea Bolognani <abologna@redhat.com>
This commit is contained in:
parent
c9d5f2d989
commit
bfb8ab1b2c
|
@ -966,8 +966,7 @@ ipsetValidator(enum attrDatatype datatype ATTRIBUTE_UNUSED,
|
||||||
{
|
{
|
||||||
const char *errmsg = NULL;
|
const char *errmsg = NULL;
|
||||||
|
|
||||||
if (virStrcpy(item->u.ipset.setname, val->c,
|
if (virStrcpyStatic(item->u.ipset.setname, val->c) == NULL) {
|
||||||
sizeof(item->u.ipset.setname)) == NULL) {
|
|
||||||
errmsg = _("ipset name is too long");
|
errmsg = _("ipset name is too long");
|
||||||
goto arg_err_exit;
|
goto arg_err_exit;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1183,7 +1183,7 @@ int virFDStreamConnectUNIX(virStreamPtr st,
|
||||||
goto error;
|
goto error;
|
||||||
sa.sun_path[0] = '\0';
|
sa.sun_path[0] = '\0';
|
||||||
} else {
|
} else {
|
||||||
if (virStrcpy(sa.sun_path, path, sizeof(sa.sun_path)) == NULL)
|
if (virStrcpyStatic(sa.sun_path, path) == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -284,8 +284,7 @@ virLogOnceInit(void)
|
||||||
*/
|
*/
|
||||||
r = gethostname(virLogHostname, sizeof(virLogHostname));
|
r = gethostname(virLogHostname, sizeof(virLogHostname));
|
||||||
if (r == -1) {
|
if (r == -1) {
|
||||||
ignore_value(virStrcpy(virLogHostname,
|
ignore_value(virStrcpyStatic(virLogHostname, "(unknown)"));
|
||||||
"(unknown)", sizeof(virLogHostname)));
|
|
||||||
} else {
|
} else {
|
||||||
NUL_TERMINATE(virLogHostname);
|
NUL_TERMINATE(virLogHostname);
|
||||||
}
|
}
|
||||||
|
@ -1027,7 +1026,7 @@ virLogOutputToJournald(virLogSourcePtr source,
|
||||||
|
|
||||||
memset(&sa, 0, sizeof(sa));
|
memset(&sa, 0, sizeof(sa));
|
||||||
sa.sun_family = AF_UNIX;
|
sa.sun_family = AF_UNIX;
|
||||||
if (!virStrcpy(sa.sun_path, "/run/systemd/journal/socket", sizeof(sa.sun_path)))
|
if (!virStrcpyStatic(sa.sun_path, "/run/systemd/journal/socket"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
memset(&mh, 0, sizeof(mh));
|
memset(&mh, 0, sizeof(mh));
|
||||||
|
|
|
@ -914,8 +914,7 @@ int virNetDevGetIndex(const char *ifname, int *ifindex)
|
||||||
|
|
||||||
memset(&ifreq, 0, sizeof(ifreq));
|
memset(&ifreq, 0, sizeof(ifreq));
|
||||||
|
|
||||||
if (virStrncpy(ifreq.ifr_name, ifname, strlen(ifname),
|
if (virStrcpyStatic(ifreq.ifr_name, ifname) == NULL) {
|
||||||
sizeof(ifreq.ifr_name)) == NULL) {
|
|
||||||
virReportSystemError(ERANGE,
|
virReportSystemError(ERANGE,
|
||||||
_("invalid interface name %s"),
|
_("invalid interface name %s"),
|
||||||
ifname);
|
ifname);
|
||||||
|
|
|
@ -475,15 +475,12 @@ xenParseXLVnuma(virConfPtr conf,
|
||||||
data++;
|
data++;
|
||||||
|
|
||||||
if (*data) {
|
if (*data) {
|
||||||
size_t len;
|
|
||||||
char vtoken[64];
|
char vtoken[64];
|
||||||
|
|
||||||
if (STRPREFIX(str, "pnode")) {
|
if (STRPREFIX(str, "pnode")) {
|
||||||
unsigned int cellid;
|
unsigned int cellid;
|
||||||
|
|
||||||
len = strlen(data);
|
if (!virStrcpyStatic(vtoken, data)) {
|
||||||
if (!virStrncpy(vtoken, data,
|
|
||||||
len, sizeof(vtoken))) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("vnuma vnode %zu pnode '%s' too long for destination"),
|
_("vnuma vnode %zu pnode '%s' too long for destination"),
|
||||||
vnodeCnt, data);
|
vnodeCnt, data);
|
||||||
|
@ -499,9 +496,7 @@ xenParseXLVnuma(virConfPtr conf,
|
||||||
}
|
}
|
||||||
pnode = cellid;
|
pnode = cellid;
|
||||||
} else if (STRPREFIX(str, "size")) {
|
} else if (STRPREFIX(str, "size")) {
|
||||||
len = strlen(data);
|
if (!virStrcpyStatic(vtoken, data)) {
|
||||||
if (!virStrncpy(vtoken, data,
|
|
||||||
len, sizeof(vtoken))) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("vnuma vnode %zu size '%s' too long for destination"),
|
_("vnuma vnode %zu size '%s' too long for destination"),
|
||||||
vnodeCnt, data);
|
vnodeCnt, data);
|
||||||
|
@ -514,9 +509,7 @@ xenParseXLVnuma(virConfPtr conf,
|
||||||
virDomainNumaSetNodeMemorySize(numa, vnodeCnt, (kbsize * 1024));
|
virDomainNumaSetNodeMemorySize(numa, vnodeCnt, (kbsize * 1024));
|
||||||
|
|
||||||
} else if (STRPREFIX(str, "vcpus")) {
|
} else if (STRPREFIX(str, "vcpus")) {
|
||||||
len = strlen(data);
|
if (!virStrcpyStatic(vtoken, data)) {
|
||||||
if (!virStrncpy(vtoken, data,
|
|
||||||
len, sizeof(vtoken))) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("vnuma vnode %zu vcpus '%s' too long for destination"),
|
_("vnuma vnode %zu vcpus '%s' too long for destination"),
|
||||||
vnodeCnt, data);
|
vnodeCnt, data);
|
||||||
|
@ -533,9 +526,7 @@ xenParseXLVnuma(virConfPtr conf,
|
||||||
size_t i, ndistances;
|
size_t i, ndistances;
|
||||||
unsigned int value;
|
unsigned int value;
|
||||||
|
|
||||||
len = strlen(data);
|
if (!virStrcpyStatic(vtoken, data)) {
|
||||||
if (!virStrncpy(vtoken, data,
|
|
||||||
len, sizeof(vtoken))) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("vnuma vnode %zu vdistances '%s' too long for destination"),
|
_("vnuma vnode %zu vdistances '%s' too long for destination"),
|
||||||
vnodeCnt, data);
|
vnodeCnt, data);
|
||||||
|
|
Loading…
Reference in New Issue