Introduce a vastly simpler VIR_INT64_STR_BUFLEN constant which is large enough for all cases where we currently use INT_BUFSIZE_BOUND. This eliminates most use of the gnulib intprops.h header. Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx> --- src/hyperv/hyperv_driver.c | 3 +- src/nwfilter/nwfilter_ebiptables_driver.c | 35 +++++++++-------------- src/nwfilter/nwfilter_learnipaddr.c | 14 ++++----- src/util/virfile.c | 9 +++--- src/util/virhostcpu.c | 3 +- src/util/virlog.c | 3 +- src/util/virnetdevbridge.c | 10 +++---- src/util/virpidfile.c | 7 ++--- src/util/virstring.h | 2 ++ tests/virsystemdtest.c | 5 ++-- tools/virsh-domain-monitor.c | 3 +- tools/virt-login-shell.c | 7 +++-- 12 files changed, 42 insertions(+), 59 deletions(-) diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index c9d22ec7c4..4677a25ff8 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -36,7 +36,6 @@ #include "openwsman.h" #include "virstring.h" #include "virkeycode.h" -#include "intprops.h" #define VIR_FROM_THIS VIR_FROM_HYPERV @@ -1339,7 +1338,7 @@ hypervDomainSendKey(virDomainPtr domain, unsigned int codeset, Msvm_Keyboard *keyboard = NULL; virBuffer query = VIR_BUFFER_INITIALIZER; hypervInvokeParamsListPtr params = NULL; - char keycodeStr[INT_BUFSIZE_BOUND(int)]; + char keycodeStr[VIR_INT64_STR_BUFLEN]; virCheckFlags(0, -1); diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfilter_ebiptables_driver.c index eec1414023..f4c192aebb 100644 --- a/src/nwfilter/nwfilter_ebiptables_driver.c +++ b/src/nwfilter/nwfilter_ebiptables_driver.c @@ -40,7 +40,6 @@ #include "virfile.h" #include "vircommand.h" #include "configmake.h" -#include "intprops.h" #include "virstring.h" #include "virfirewall.h" @@ -820,10 +819,9 @@ iptablesHandleIPHdr(virFirewallPtr fw, bool directionIn, bool *skipRule, bool *skipMatch) { - char ipaddr[INET6_ADDRSTRLEN], - ipaddralt[INET6_ADDRSTRLEN], - number[MAX(INT_BUFSIZE_BOUND(uint32_t), - INT_BUFSIZE_BOUND(int))]; + char ipaddr[INET6_ADDRSTRLEN]; + char ipaddralt[INET6_ADDRSTRLEN]; + char number[VIR_INT64_STR_BUFLEN]; const char *src = "--source"; const char *dst = "--destination"; const char *srcrange = "--src-range"; @@ -968,8 +966,7 @@ iptablesHandleIPHdrAfterStateMatch(virFirewallPtr fw, ipHdrDataDefPtr ipHdr, bool directionIn) { - char number[MAX(INT_BUFSIZE_BOUND(uint32_t), - INT_BUFSIZE_BOUND(int))]; + char number[VIR_INT64_STR_BUFLEN]; char str[MAX_IPSET_NAME_LENGTH]; if (HAS_ENTRY_ITEM(&ipHdr->dataIPSet) && @@ -1152,10 +1149,8 @@ _iptablesCreateRuleInstance(virFirewallPtr fw, bool maySkipICMP) { char chain[MAX_CHAINNAME_LENGTH]; - char number[MAX(INT_BUFSIZE_BOUND(uint32_t), - INT_BUFSIZE_BOUND(int))]; - char numberalt[MAX(INT_BUFSIZE_BOUND(uint32_t), - INT_BUFSIZE_BOUND(int))]; + char number[VIR_INT64_STR_BUFLEN]; + char numberalt[VIR_INT64_STR_BUFLEN]; const char *target; bool srcMacSkipped = false; bool skipRule = false; @@ -1789,16 +1784,14 @@ ebtablesCreateRuleInstance(virFirewallPtr fw, virNWFilterVarCombIterPtr vars, bool reverse) { - char macaddr[VIR_MAC_STRING_BUFLEN], - ipaddr[INET_ADDRSTRLEN], - ipmask[INET_ADDRSTRLEN], - ipv6addr[INET6_ADDRSTRLEN], - number[MAX(INT_BUFSIZE_BOUND(uint32_t), - INT_BUFSIZE_BOUND(int))], - numberalt[MAX(INT_BUFSIZE_BOUND(uint32_t), - INT_BUFSIZE_BOUND(int))], - field[MAX(VIR_MAC_STRING_BUFLEN, INET6_ADDRSTRLEN)], - fieldalt[MAX(VIR_MAC_STRING_BUFLEN, INET6_ADDRSTRLEN)]; + char macaddr[VIR_MAC_STRING_BUFLEN]; + char ipaddr[INET_ADDRSTRLEN]; + char ipmask[INET_ADDRSTRLEN]; + char ipv6addr[INET6_ADDRSTRLEN]; + char number[VIR_INT64_STR_BUFLEN]; + char numberalt[VIR_INT64_STR_BUFLEN]; + char field[VIR_INT64_STR_BUFLEN]; + char fieldalt[VIR_INT64_STR_BUFLEN]; char chain[MAX_CHAINNAME_LENGTH]; const char *target; bool hasMask = false; diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_learnipaddr.c index 46ef65401c..5791724cf4 100644 --- a/src/nwfilter/nwfilter_learnipaddr.c +++ b/src/nwfilter/nwfilter_learnipaddr.c @@ -39,7 +39,6 @@ #include "internal.h" -#include "intprops.h" #include "virbuffer.h" #include "viralloc.h" #include "virlog.h" @@ -59,10 +58,6 @@ VIR_LOG_INIT("nwfilter.nwfilter_learnipaddr"); -#define IFINDEX2STR(VARNAME, ifindex) \ - char VARNAME[INT_BUFSIZE_BOUND(ifindex)]; \ - g_snprintf(VARNAME, sizeof(VARNAME), "%d", ifindex); - #define PKT_TIMEOUT_MS 500 /* ms */ /* structure of an ARP request/reply message */ @@ -239,7 +234,7 @@ static int virNWFilterRegisterLearnReq(virNWFilterIPAddrLearnReqPtr req) { int res = -1; - IFINDEX2STR(ifindex_str, req->ifindex); + g_autofree char *ifindex_str = g_strdup_printf("%d", req->ifindex); virMutexLock(&pendingLearnReqLock); @@ -260,6 +255,7 @@ virNWFilterTerminateLearnReq(const char *ifname) int rc = -1; int ifindex; virNWFilterIPAddrLearnReqPtr req; + g_autofree char *ifindex_str = NULL; /* It's possible that it's already been removed as a result of * virNWFilterDeregisterLearnReq during learnIPAddressThread() exit @@ -274,7 +270,7 @@ virNWFilterTerminateLearnReq(const char *ifname) return rc; } - IFINDEX2STR(ifindex_str, ifindex); + ifindex_str = g_strdup_printf("%d", ifindex); virMutexLock(&pendingLearnReqLock); @@ -294,7 +290,7 @@ bool virNWFilterHasLearnReq(int ifindex) { void *res; - IFINDEX2STR(ifindex_str, ifindex); + g_autofree char *ifindex_str = g_strdup_printf("%d", ifindex); virMutexLock(&pendingLearnReqLock); @@ -319,7 +315,7 @@ static virNWFilterIPAddrLearnReqPtr virNWFilterDeregisterLearnReq(int ifindex) { virNWFilterIPAddrLearnReqPtr res; - IFINDEX2STR(ifindex_str, ifindex); + g_autofree char *ifindex_str = g_strdup_printf("%d", ifindex); virMutexLock(&pendingLearnReqLock); diff --git a/src/util/virfile.c b/src/util/virfile.c index 5acac85bb9..6eaabf5371 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -68,7 +68,6 @@ #endif #include "configmake.h" -#include "intprops.h" #include "viralloc.h" #include "vircommand.h" #include "virerror.h" @@ -4067,7 +4066,7 @@ virFileReadValueInt(int *value, const char *format, ...) if (!virFileExists(path)) return -2; - if (virFileReadAll(path, INT_BUFSIZE_BOUND(*value), &str) < 0) + if (virFileReadAll(path, VIR_INT64_STR_BUFLEN, &str) < 0) return -1; virStringTrimOptionalNewline(str); @@ -4107,7 +4106,7 @@ virFileReadValueUint(unsigned int *value, const char *format, ...) if (!virFileExists(path)) return -2; - if (virFileReadAll(path, INT_BUFSIZE_BOUND(*value), &str) < 0) + if (virFileReadAll(path, VIR_INT64_STR_BUFLEN, &str) < 0) return -1; virStringTrimOptionalNewline(str); @@ -4147,7 +4146,7 @@ virFileReadValueUllong(unsigned long long *value, const char *format, ...) if (!virFileExists(path)) return -2; - if (virFileReadAll(path, INT_BUFSIZE_BOUND(*value), &str) < 0) + if (virFileReadAll(path, VIR_INT64_STR_BUFLEN, &str) < 0) return -1; virStringTrimOptionalNewline(str); @@ -4188,7 +4187,7 @@ virFileReadValueScaledInt(unsigned long long *value, const char *format, ...) if (!virFileExists(path)) return -2; - if (virFileReadAll(path, INT_BUFSIZE_BOUND(*value), &str) < 0) + if (virFileReadAll(path, VIR_INT64_STR_BUFLEN, &str) < 0) return -1; virStringTrimOptionalNewline(str); diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c index 7f14340f49..f3adc1b4ae 100644 --- a/src/util/virhostcpu.c +++ b/src/util/virhostcpu.c @@ -43,7 +43,6 @@ #include "virhostcpupriv.h" #include "physmem.h" #include "virerror.h" -#include "intprops.h" #include "virarch.h" #include "virfile.h" #include "virtypedparam.h" @@ -775,7 +774,7 @@ virHostCPUGetStatsLinux(FILE *procstat, char line[1024]; unsigned long long usr, ni, sys, idle, iowait; unsigned long long irq, softirq, steal, guest, guest_nice; - char cpu_header[4 + INT_BUFSIZE_BOUND(cpuNum)]; + char cpu_header[4 + VIR_INT64_STR_BUFLEN]; if ((*nparams) == 0) { /* Current number of cpu stats supported by linux */ diff --git a/src/util/virlog.c b/src/util/virlog.c index 8a9fb34161..ddc3ac1edb 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -45,7 +45,6 @@ #include "virthread.h" #include "virfile.h" #include "virtime.h" -#include "intprops.h" #include "virstring.h" #include "configmake.h" @@ -832,7 +831,7 @@ virLogNewOutputToSyslog(virLogPriority priority, # define IOVEC_SET_STRING(iov, str) IOVEC_SET(iov, str, strlen(str)) /* Used for conversion of numbers to strings, and for length of binary data */ -# define JOURNAL_BUF_SIZE (MAX(INT_BUFSIZE_BOUND(int), sizeof(uint64_t))) +# define JOURNAL_BUF_SIZE (MAX(VIR_INT64_STR_BUFLEN, sizeof(uint64_t))) struct journalState { diff --git a/src/util/virnetdevbridge.c b/src/util/virnetdevbridge.c index 3a7a6dc730..a37bcb4004 100644 --- a/src/util/virnetdevbridge.c +++ b/src/util/virnetdevbridge.c @@ -25,7 +25,6 @@ #include "virfile.h" #include "viralloc.h" #include "virlog.h" -#include "intprops.h" #include "virstring.h" #include <sys/ioctl.h> @@ -125,8 +124,7 @@ static int virNetDevBridgeSet(const char *brname, path = g_strdup_printf(SYSFS_NET_DIR "%s/bridge/%s", brname, paramname); if (virFileExists(path)) { - char valuestr[INT_BUFSIZE_BOUND(value)]; - g_snprintf(valuestr, sizeof(valuestr), "%lu", value); + g_autofree char *valuestr = g_strdup_printf("%lu", value); if (virFileWriteStr(path, valuestr, 0) >= 0) return 0; VIR_DEBUG("Unable to set bridge %s %s via sysfs", brname, paramname); @@ -169,7 +167,7 @@ static int virNetDevBridgeGet(const char *brname, if (virFileExists(path)) { g_autofree char *valuestr = NULL; - if (virFileReadAll(path, INT_BUFSIZE_BOUND(unsigned long), + if (virFileReadAll(path, VIR_INT64_STR_BUFLEN, &valuestr) < 0) return -1; @@ -215,7 +213,7 @@ virNetDevBridgePortSet(const char *brname, const char *paramname, unsigned long value) { - char valuestr[INT_BUFSIZE_BOUND(value)]; + char valuestr[VIR_INT64_STR_BUFLEN]; int ret = -1; g_autofree char *path = NULL; @@ -251,7 +249,7 @@ virNetDevBridgePortGet(const char *brname, path = g_strdup_printf(SYSFS_NET_DIR "%s/brif/%s/%s", brname, ifname, paramname); - if (virFileReadAll(path, INT_BUFSIZE_BOUND(unsigned long), &valuestr) < 0) + if (virFileReadAll(path, VIR_INT64_STR_BUFLEN, &valuestr) < 0) return -1; if (virStrToLong_ul(valuestr, NULL, 10, value) < 0) { diff --git a/src/util/virpidfile.c b/src/util/virpidfile.c index b08e0d8d52..a8a743504d 100644 --- a/src/util/virpidfile.c +++ b/src/util/virpidfile.c @@ -31,7 +31,6 @@ #include "virfile.h" #include "viralloc.h" #include "virutil.h" -#include "intprops.h" #include "virlog.h" #include "virerror.h" #include "virstring.h" @@ -57,7 +56,7 @@ int virPidFileWritePath(const char *pidfile, { int rc; int fd; - char pidstr[INT_BUFSIZE_BOUND(pid)]; + char pidstr[VIR_INT64_STR_BUFLEN]; if ((fd = open(pidfile, O_WRONLY | O_CREAT | O_TRUNC, @@ -110,7 +109,7 @@ int virPidFileReadPath(const char *path, int rc; ssize_t bytes; long long pid_value = 0; - char pidstr[INT_BUFSIZE_BOUND(pid_value)]; + char pidstr[VIR_INT64_STR_BUFLEN]; char *endptr = NULL; *pid = 0; @@ -333,7 +332,7 @@ int virPidFileAcquirePath(const char *path, pid_t pid) { int fd = -1; - char pidstr[INT_BUFSIZE_BOUND(pid)]; + char pidstr[VIR_INT64_STR_BUFLEN]; if (path[0] == '\0') return 0; diff --git a/src/util/virstring.h b/src/util/virstring.h index a2cd92cf83..360c68395c 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -22,6 +22,8 @@ #include "internal.h" +#define VIR_INT64_STR_BUFLEN 21 + char **virStringSplitCount(const char *string, const char *delim, size_t max_tokens, diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c index 26876850b8..a9b02af7db 100644 --- a/tests/virsystemdtest.c +++ b/tests/virsystemdtest.c @@ -33,7 +33,6 @@ # include "virlog.h" # include "virmock.h" # include "rpc/virnetsocket.h" -# include "intprops.h" # define VIR_FROM_THIS VIR_FROM_NONE VIR_LOG_INIT("tests.systemdtest"); @@ -548,8 +547,8 @@ testActivation(bool useNames) size_t nsockIP; int ret = -1; size_t i; - char nfdstr[INT_BUFSIZE_BOUND(size_t)]; - char pidstr[INT_BUFSIZE_BOUND(pid_t)]; + char nfdstr[VIR_INT64_STR_BUFLEN]; + char pidstr[VIR_INT64_STR_BUFLEN]; virSystemdActivationMap map[2]; int *fds = NULL; size_t nfds = 0; diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index e357635757..efcdc613c6 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -29,7 +29,6 @@ #include "internal.h" #include "conf/virdomainobjlist.h" -#include "intprops.h" #include "viralloc.h" #include "virmacaddr.h" #include "virxml.h" @@ -1964,7 +1963,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd) bool ret = false; virshDomainListPtr list = NULL; virDomainPtr dom; - char id_buf[INT_BUFSIZE_BOUND(unsigned int)]; + char id_buf[VIR_INT64_STR_BUFLEN]; unsigned int id; unsigned int flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE; vshTablePtr table = NULL; diff --git a/tools/virt-login-shell.c b/tools/virt-login-shell.c index 7d1e0ccc8a..cf4a249f0a 100644 --- a/tools/virt-login-shell.c +++ b/tools/virt-login-shell.c @@ -33,11 +33,12 @@ * so don't introduce a link time dep, which we must avoid */ #include "gnulib/lib/configmake.h" -#include "gnulib/lib/intprops.h" + +#define VIR_INT64_STR_BUFLEN 21 int main(int argc, char **argv) { - char uidstr[INT_BUFSIZE_BOUND(uid_t)]; - char gidstr[INT_BUFSIZE_BOUND(gid_t)]; + char uidstr[VIR_INT64_STR_BUFLEN]; + char gidstr[VIR_INT64_STR_BUFLEN]; const char * newargv[6]; size_t nargs = 0; char *newenv[] = { -- 2.24.1