]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
src: replace use of INT_BUFSIZE_BOUND macros
authorDaniel P. Berrangé <berrange@redhat.com>
Tue, 14 Jan 2020 13:30:07 +0000 (13:30 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Fri, 17 Jan 2020 09:58:43 +0000 (09:58 +0000)
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.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
12 files changed:
src/hyperv/hyperv_driver.c
src/nwfilter/nwfilter_ebiptables_driver.c
src/nwfilter/nwfilter_learnipaddr.c
src/util/virfile.c
src/util/virhostcpu.c
src/util/virlog.c
src/util/virnetdevbridge.c
src/util/virpidfile.c
src/util/virstring.h
tests/virsystemdtest.c
tools/virsh-domain-monitor.c
tools/virt-login-shell.c

index c9d22ec7c4d7c77f41a4462ece0c10ba97e6d183..4677a25ff827148b181fda697d37244c0c59205b 100644 (file)
@@ -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);
 
index eec14140238ccf9135551c89a08b5cdef3282b61..f4c192aebbdcc012cae5bdcf8cd871004fcda3bd 100644 (file)
@@ -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;
index 46ef65401c31c057ad2666e39fd95482ff2e7abf..5791724cf4470d6196c3786fc1c6e6d7963f62f2 100644 (file)
@@ -39,7 +39,6 @@
 
 #include "internal.h"
 
-#include "intprops.h"
 #include "virbuffer.h"
 #include "viralloc.h"
 #include "virlog.h"
 
 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);
 
index 5acac85bb9ecb903e9cffe6cbaee5d8c0fe02af8..6eaabf5371d94fbaed92a6b526b7f1eb26d92578 100644 (file)
@@ -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);
index 0ed2c9e9b4b5ee22da1f9db68d4c26769ccd3c05..dd5016d4d27d0f70d380e983c567d55879db98d9 100644 (file)
@@ -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"
@@ -791,7 +790,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 */
index 8a9fb34161b598da491ae10381e954bd906e7bfc..ddc3ac1edb5fc1726aac2899e5703751b8cf9a7a 100644 (file)
@@ -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
 {
index 3a7a6dc7302a1e47760e89792ac25711fde45a5c..a37bcb4004762c4f0f9f65397c0ae984f4371e09 100644 (file)
@@ -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) {
index b08e0d8d520cebc21431ff785c65f062e0662e81..a8a743504da55a5bcc369c060ab86b5696f9d32e 100644 (file)
@@ -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;
index a2cd92cf839ff32b09a5eed866d1111d39603736..360c68395ce920546874891e26ace532f01fc020 100644 (file)
@@ -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,
index 26876850b8cc019dcd196ae41fcde340c61f3ce5..a9b02af7dbdfd7976fb0539f6f1744d91d357f4d 100644 (file)
@@ -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;
index e357635757002c54859be993c7211d69762cc505..efcdc613c6f826d1fd7a82269386ac666c3d2832 100644 (file)
@@ -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;
index 7d1e0ccc8a359d360767c2e19b1dfaa011f71ea4..cf4a249f0a14379acc95d17aedbaa1e35764f2d7 100644 (file)
  * 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[] = {