提交 bfb8ab1b 编写于 作者: A Andrea Bolognani

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: NAndrea Bolognani <abologna@redhat.com>
上级 c9d5f2d9
......@@ -966,8 +966,7 @@ ipsetValidator(enum attrDatatype datatype ATTRIBUTE_UNUSED,
{
const char *errmsg = NULL;
if (virStrcpy(item->u.ipset.setname, val->c,
sizeof(item->u.ipset.setname)) == NULL) {
if (virStrcpyStatic(item->u.ipset.setname, val->c) == NULL) {
errmsg = _("ipset name is too long");
goto arg_err_exit;
}
......
......@@ -1183,7 +1183,7 @@ int virFDStreamConnectUNIX(virStreamPtr st,
goto error;
sa.sun_path[0] = '\0';
} else {
if (virStrcpy(sa.sun_path, path, sizeof(sa.sun_path)) == NULL)
if (virStrcpyStatic(sa.sun_path, path) == NULL)
goto error;
}
......
......@@ -284,8 +284,7 @@ virLogOnceInit(void)
*/
r = gethostname(virLogHostname, sizeof(virLogHostname));
if (r == -1) {
ignore_value(virStrcpy(virLogHostname,
"(unknown)", sizeof(virLogHostname)));
ignore_value(virStrcpyStatic(virLogHostname, "(unknown)"));
} else {
NUL_TERMINATE(virLogHostname);
}
......@@ -1027,7 +1026,7 @@ virLogOutputToJournald(virLogSourcePtr source,
memset(&sa, 0, sizeof(sa));
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;
memset(&mh, 0, sizeof(mh));
......
......@@ -914,8 +914,7 @@ int virNetDevGetIndex(const char *ifname, int *ifindex)
memset(&ifreq, 0, sizeof(ifreq));
if (virStrncpy(ifreq.ifr_name, ifname, strlen(ifname),
sizeof(ifreq.ifr_name)) == NULL) {
if (virStrcpyStatic(ifreq.ifr_name, ifname) == NULL) {
virReportSystemError(ERANGE,
_("invalid interface name %s"),
ifname);
......
......@@ -475,15 +475,12 @@ xenParseXLVnuma(virConfPtr conf,
data++;
if (*data) {
size_t len;
char vtoken[64];
if (STRPREFIX(str, "pnode")) {
unsigned int cellid;
len = strlen(data);
if (!virStrncpy(vtoken, data,
len, sizeof(vtoken))) {
if (!virStrcpyStatic(vtoken, data)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("vnuma vnode %zu pnode '%s' too long for destination"),
vnodeCnt, data);
......@@ -499,9 +496,7 @@ xenParseXLVnuma(virConfPtr conf,
}
pnode = cellid;
} else if (STRPREFIX(str, "size")) {
len = strlen(data);
if (!virStrncpy(vtoken, data,
len, sizeof(vtoken))) {
if (!virStrcpyStatic(vtoken, data)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("vnuma vnode %zu size '%s' too long for destination"),
vnodeCnt, data);
......@@ -514,9 +509,7 @@ xenParseXLVnuma(virConfPtr conf,
virDomainNumaSetNodeMemorySize(numa, vnodeCnt, (kbsize * 1024));
} else if (STRPREFIX(str, "vcpus")) {
len = strlen(data);
if (!virStrncpy(vtoken, data,
len, sizeof(vtoken))) {
if (!virStrcpyStatic(vtoken, data)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("vnuma vnode %zu vcpus '%s' too long for destination"),
vnodeCnt, data);
......@@ -533,9 +526,7 @@ xenParseXLVnuma(virConfPtr conf,
size_t i, ndistances;
unsigned int value;
len = strlen(data);
if (!virStrncpy(vtoken, data,
len, sizeof(vtoken))) {
if (!virStrcpyStatic(vtoken, data)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("vnuma vnode %zu vdistances '%s' too long for destination"),
vnodeCnt, data);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册