src: replace use of INT_BUFSIZE_BOUND macros

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>
This commit is contained in:
Daniel P. Berrangé 2020-01-14 13:30:07 +00:00
parent a1cd25b919
commit 117353f9e5
12 changed files with 42 additions and 59 deletions

View File

@ -36,7 +36,6 @@
#include "openwsman.h" #include "openwsman.h"
#include "virstring.h" #include "virstring.h"
#include "virkeycode.h" #include "virkeycode.h"
#include "intprops.h"
#define VIR_FROM_THIS VIR_FROM_HYPERV #define VIR_FROM_THIS VIR_FROM_HYPERV
@ -1339,7 +1338,7 @@ hypervDomainSendKey(virDomainPtr domain, unsigned int codeset,
Msvm_Keyboard *keyboard = NULL; Msvm_Keyboard *keyboard = NULL;
virBuffer query = VIR_BUFFER_INITIALIZER; virBuffer query = VIR_BUFFER_INITIALIZER;
hypervInvokeParamsListPtr params = NULL; hypervInvokeParamsListPtr params = NULL;
char keycodeStr[INT_BUFSIZE_BOUND(int)]; char keycodeStr[VIR_INT64_STR_BUFLEN];
virCheckFlags(0, -1); virCheckFlags(0, -1);

View File

@ -40,7 +40,6 @@
#include "virfile.h" #include "virfile.h"
#include "vircommand.h" #include "vircommand.h"
#include "configmake.h" #include "configmake.h"
#include "intprops.h"
#include "virstring.h" #include "virstring.h"
#include "virfirewall.h" #include "virfirewall.h"
@ -820,10 +819,9 @@ iptablesHandleIPHdr(virFirewallPtr fw,
bool directionIn, bool directionIn,
bool *skipRule, bool *skipMatch) bool *skipRule, bool *skipMatch)
{ {
char ipaddr[INET6_ADDRSTRLEN], char ipaddr[INET6_ADDRSTRLEN];
ipaddralt[INET6_ADDRSTRLEN], char ipaddralt[INET6_ADDRSTRLEN];
number[MAX(INT_BUFSIZE_BOUND(uint32_t), char number[VIR_INT64_STR_BUFLEN];
INT_BUFSIZE_BOUND(int))];
const char *src = "--source"; const char *src = "--source";
const char *dst = "--destination"; const char *dst = "--destination";
const char *srcrange = "--src-range"; const char *srcrange = "--src-range";
@ -968,8 +966,7 @@ iptablesHandleIPHdrAfterStateMatch(virFirewallPtr fw,
ipHdrDataDefPtr ipHdr, ipHdrDataDefPtr ipHdr,
bool directionIn) bool directionIn)
{ {
char number[MAX(INT_BUFSIZE_BOUND(uint32_t), char number[VIR_INT64_STR_BUFLEN];
INT_BUFSIZE_BOUND(int))];
char str[MAX_IPSET_NAME_LENGTH]; char str[MAX_IPSET_NAME_LENGTH];
if (HAS_ENTRY_ITEM(&ipHdr->dataIPSet) && if (HAS_ENTRY_ITEM(&ipHdr->dataIPSet) &&
@ -1152,10 +1149,8 @@ _iptablesCreateRuleInstance(virFirewallPtr fw,
bool maySkipICMP) bool maySkipICMP)
{ {
char chain[MAX_CHAINNAME_LENGTH]; char chain[MAX_CHAINNAME_LENGTH];
char number[MAX(INT_BUFSIZE_BOUND(uint32_t), char number[VIR_INT64_STR_BUFLEN];
INT_BUFSIZE_BOUND(int))]; char numberalt[VIR_INT64_STR_BUFLEN];
char numberalt[MAX(INT_BUFSIZE_BOUND(uint32_t),
INT_BUFSIZE_BOUND(int))];
const char *target; const char *target;
bool srcMacSkipped = false; bool srcMacSkipped = false;
bool skipRule = false; bool skipRule = false;
@ -1789,16 +1784,14 @@ ebtablesCreateRuleInstance(virFirewallPtr fw,
virNWFilterVarCombIterPtr vars, virNWFilterVarCombIterPtr vars,
bool reverse) bool reverse)
{ {
char macaddr[VIR_MAC_STRING_BUFLEN], char macaddr[VIR_MAC_STRING_BUFLEN];
ipaddr[INET_ADDRSTRLEN], char ipaddr[INET_ADDRSTRLEN];
ipmask[INET_ADDRSTRLEN], char ipmask[INET_ADDRSTRLEN];
ipv6addr[INET6_ADDRSTRLEN], char ipv6addr[INET6_ADDRSTRLEN];
number[MAX(INT_BUFSIZE_BOUND(uint32_t), char number[VIR_INT64_STR_BUFLEN];
INT_BUFSIZE_BOUND(int))], char numberalt[VIR_INT64_STR_BUFLEN];
numberalt[MAX(INT_BUFSIZE_BOUND(uint32_t), char field[VIR_INT64_STR_BUFLEN];
INT_BUFSIZE_BOUND(int))], char fieldalt[VIR_INT64_STR_BUFLEN];
field[MAX(VIR_MAC_STRING_BUFLEN, INET6_ADDRSTRLEN)],
fieldalt[MAX(VIR_MAC_STRING_BUFLEN, INET6_ADDRSTRLEN)];
char chain[MAX_CHAINNAME_LENGTH]; char chain[MAX_CHAINNAME_LENGTH];
const char *target; const char *target;
bool hasMask = false; bool hasMask = false;

View File

@ -39,7 +39,6 @@
#include "internal.h" #include "internal.h"
#include "intprops.h"
#include "virbuffer.h" #include "virbuffer.h"
#include "viralloc.h" #include "viralloc.h"
#include "virlog.h" #include "virlog.h"
@ -59,10 +58,6 @@
VIR_LOG_INIT("nwfilter.nwfilter_learnipaddr"); 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 */ #define PKT_TIMEOUT_MS 500 /* ms */
/* structure of an ARP request/reply message */ /* structure of an ARP request/reply message */
@ -239,7 +234,7 @@ static int
virNWFilterRegisterLearnReq(virNWFilterIPAddrLearnReqPtr req) virNWFilterRegisterLearnReq(virNWFilterIPAddrLearnReqPtr req)
{ {
int res = -1; int res = -1;
IFINDEX2STR(ifindex_str, req->ifindex); g_autofree char *ifindex_str = g_strdup_printf("%d", req->ifindex);
virMutexLock(&pendingLearnReqLock); virMutexLock(&pendingLearnReqLock);
@ -260,6 +255,7 @@ virNWFilterTerminateLearnReq(const char *ifname)
int rc = -1; int rc = -1;
int ifindex; int ifindex;
virNWFilterIPAddrLearnReqPtr req; virNWFilterIPAddrLearnReqPtr req;
g_autofree char *ifindex_str = NULL;
/* It's possible that it's already been removed as a result of /* It's possible that it's already been removed as a result of
* virNWFilterDeregisterLearnReq during learnIPAddressThread() exit * virNWFilterDeregisterLearnReq during learnIPAddressThread() exit
@ -274,7 +270,7 @@ virNWFilterTerminateLearnReq(const char *ifname)
return rc; return rc;
} }
IFINDEX2STR(ifindex_str, ifindex); ifindex_str = g_strdup_printf("%d", ifindex);
virMutexLock(&pendingLearnReqLock); virMutexLock(&pendingLearnReqLock);
@ -294,7 +290,7 @@ bool
virNWFilterHasLearnReq(int ifindex) virNWFilterHasLearnReq(int ifindex)
{ {
void *res; void *res;
IFINDEX2STR(ifindex_str, ifindex); g_autofree char *ifindex_str = g_strdup_printf("%d", ifindex);
virMutexLock(&pendingLearnReqLock); virMutexLock(&pendingLearnReqLock);
@ -319,7 +315,7 @@ static virNWFilterIPAddrLearnReqPtr
virNWFilterDeregisterLearnReq(int ifindex) virNWFilterDeregisterLearnReq(int ifindex)
{ {
virNWFilterIPAddrLearnReqPtr res; virNWFilterIPAddrLearnReqPtr res;
IFINDEX2STR(ifindex_str, ifindex); g_autofree char *ifindex_str = g_strdup_printf("%d", ifindex);
virMutexLock(&pendingLearnReqLock); virMutexLock(&pendingLearnReqLock);

View File

@ -68,7 +68,6 @@
#endif #endif
#include "configmake.h" #include "configmake.h"
#include "intprops.h"
#include "viralloc.h" #include "viralloc.h"
#include "vircommand.h" #include "vircommand.h"
#include "virerror.h" #include "virerror.h"
@ -4067,7 +4066,7 @@ virFileReadValueInt(int *value, const char *format, ...)
if (!virFileExists(path)) if (!virFileExists(path))
return -2; return -2;
if (virFileReadAll(path, INT_BUFSIZE_BOUND(*value), &str) < 0) if (virFileReadAll(path, VIR_INT64_STR_BUFLEN, &str) < 0)
return -1; return -1;
virStringTrimOptionalNewline(str); virStringTrimOptionalNewline(str);
@ -4107,7 +4106,7 @@ virFileReadValueUint(unsigned int *value, const char *format, ...)
if (!virFileExists(path)) if (!virFileExists(path))
return -2; return -2;
if (virFileReadAll(path, INT_BUFSIZE_BOUND(*value), &str) < 0) if (virFileReadAll(path, VIR_INT64_STR_BUFLEN, &str) < 0)
return -1; return -1;
virStringTrimOptionalNewline(str); virStringTrimOptionalNewline(str);
@ -4147,7 +4146,7 @@ virFileReadValueUllong(unsigned long long *value, const char *format, ...)
if (!virFileExists(path)) if (!virFileExists(path))
return -2; return -2;
if (virFileReadAll(path, INT_BUFSIZE_BOUND(*value), &str) < 0) if (virFileReadAll(path, VIR_INT64_STR_BUFLEN, &str) < 0)
return -1; return -1;
virStringTrimOptionalNewline(str); virStringTrimOptionalNewline(str);
@ -4188,7 +4187,7 @@ virFileReadValueScaledInt(unsigned long long *value, const char *format, ...)
if (!virFileExists(path)) if (!virFileExists(path))
return -2; return -2;
if (virFileReadAll(path, INT_BUFSIZE_BOUND(*value), &str) < 0) if (virFileReadAll(path, VIR_INT64_STR_BUFLEN, &str) < 0)
return -1; return -1;
virStringTrimOptionalNewline(str); virStringTrimOptionalNewline(str);

View File

@ -43,7 +43,6 @@
#include "virhostcpupriv.h" #include "virhostcpupriv.h"
#include "physmem.h" #include "physmem.h"
#include "virerror.h" #include "virerror.h"
#include "intprops.h"
#include "virarch.h" #include "virarch.h"
#include "virfile.h" #include "virfile.h"
#include "virtypedparam.h" #include "virtypedparam.h"
@ -791,7 +790,7 @@ virHostCPUGetStatsLinux(FILE *procstat,
char line[1024]; char line[1024];
unsigned long long usr, ni, sys, idle, iowait; unsigned long long usr, ni, sys, idle, iowait;
unsigned long long irq, softirq, steal, guest, guest_nice; 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) { if ((*nparams) == 0) {
/* Current number of cpu stats supported by linux */ /* Current number of cpu stats supported by linux */

View File

@ -45,7 +45,6 @@
#include "virthread.h" #include "virthread.h"
#include "virfile.h" #include "virfile.h"
#include "virtime.h" #include "virtime.h"
#include "intprops.h"
#include "virstring.h" #include "virstring.h"
#include "configmake.h" #include "configmake.h"
@ -832,7 +831,7 @@ virLogNewOutputToSyslog(virLogPriority priority,
# define IOVEC_SET_STRING(iov, str) IOVEC_SET(iov, str, strlen(str)) # 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 */ /* 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 struct journalState
{ {

View File

@ -25,7 +25,6 @@
#include "virfile.h" #include "virfile.h"
#include "viralloc.h" #include "viralloc.h"
#include "virlog.h" #include "virlog.h"
#include "intprops.h"
#include "virstring.h" #include "virstring.h"
#include <sys/ioctl.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); path = g_strdup_printf(SYSFS_NET_DIR "%s/bridge/%s", brname, paramname);
if (virFileExists(path)) { if (virFileExists(path)) {
char valuestr[INT_BUFSIZE_BOUND(value)]; g_autofree char *valuestr = g_strdup_printf("%lu", value);
g_snprintf(valuestr, sizeof(valuestr), "%lu", value);
if (virFileWriteStr(path, valuestr, 0) >= 0) if (virFileWriteStr(path, valuestr, 0) >= 0)
return 0; return 0;
VIR_DEBUG("Unable to set bridge %s %s via sysfs", brname, paramname); 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)) { if (virFileExists(path)) {
g_autofree char *valuestr = NULL; g_autofree char *valuestr = NULL;
if (virFileReadAll(path, INT_BUFSIZE_BOUND(unsigned long), if (virFileReadAll(path, VIR_INT64_STR_BUFLEN,
&valuestr) < 0) &valuestr) < 0)
return -1; return -1;
@ -215,7 +213,7 @@ virNetDevBridgePortSet(const char *brname,
const char *paramname, const char *paramname,
unsigned long value) unsigned long value)
{ {
char valuestr[INT_BUFSIZE_BOUND(value)]; char valuestr[VIR_INT64_STR_BUFLEN];
int ret = -1; int ret = -1;
g_autofree char *path = NULL; 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, path = g_strdup_printf(SYSFS_NET_DIR "%s/brif/%s/%s", brname, ifname,
paramname); paramname);
if (virFileReadAll(path, INT_BUFSIZE_BOUND(unsigned long), &valuestr) < 0) if (virFileReadAll(path, VIR_INT64_STR_BUFLEN, &valuestr) < 0)
return -1; return -1;
if (virStrToLong_ul(valuestr, NULL, 10, value) < 0) { if (virStrToLong_ul(valuestr, NULL, 10, value) < 0) {

View File

@ -31,7 +31,6 @@
#include "virfile.h" #include "virfile.h"
#include "viralloc.h" #include "viralloc.h"
#include "virutil.h" #include "virutil.h"
#include "intprops.h"
#include "virlog.h" #include "virlog.h"
#include "virerror.h" #include "virerror.h"
#include "virstring.h" #include "virstring.h"
@ -57,7 +56,7 @@ int virPidFileWritePath(const char *pidfile,
{ {
int rc; int rc;
int fd; int fd;
char pidstr[INT_BUFSIZE_BOUND(pid)]; char pidstr[VIR_INT64_STR_BUFLEN];
if ((fd = open(pidfile, if ((fd = open(pidfile,
O_WRONLY | O_CREAT | O_TRUNC, O_WRONLY | O_CREAT | O_TRUNC,
@ -110,7 +109,7 @@ int virPidFileReadPath(const char *path,
int rc; int rc;
ssize_t bytes; ssize_t bytes;
long long pid_value = 0; long long pid_value = 0;
char pidstr[INT_BUFSIZE_BOUND(pid_value)]; char pidstr[VIR_INT64_STR_BUFLEN];
char *endptr = NULL; char *endptr = NULL;
*pid = 0; *pid = 0;
@ -333,7 +332,7 @@ int virPidFileAcquirePath(const char *path,
pid_t pid) pid_t pid)
{ {
int fd = -1; int fd = -1;
char pidstr[INT_BUFSIZE_BOUND(pid)]; char pidstr[VIR_INT64_STR_BUFLEN];
if (path[0] == '\0') if (path[0] == '\0')
return 0; return 0;

View File

@ -22,6 +22,8 @@
#include "internal.h" #include "internal.h"
#define VIR_INT64_STR_BUFLEN 21
char **virStringSplitCount(const char *string, char **virStringSplitCount(const char *string,
const char *delim, const char *delim,
size_t max_tokens, size_t max_tokens,

View File

@ -33,7 +33,6 @@
# include "virlog.h" # include "virlog.h"
# include "virmock.h" # include "virmock.h"
# include "rpc/virnetsocket.h" # include "rpc/virnetsocket.h"
# include "intprops.h"
# define VIR_FROM_THIS VIR_FROM_NONE # define VIR_FROM_THIS VIR_FROM_NONE
VIR_LOG_INIT("tests.systemdtest"); VIR_LOG_INIT("tests.systemdtest");
@ -548,8 +547,8 @@ testActivation(bool useNames)
size_t nsockIP; size_t nsockIP;
int ret = -1; int ret = -1;
size_t i; size_t i;
char nfdstr[INT_BUFSIZE_BOUND(size_t)]; char nfdstr[VIR_INT64_STR_BUFLEN];
char pidstr[INT_BUFSIZE_BOUND(pid_t)]; char pidstr[VIR_INT64_STR_BUFLEN];
virSystemdActivationMap map[2]; virSystemdActivationMap map[2];
int *fds = NULL; int *fds = NULL;
size_t nfds = 0; size_t nfds = 0;

View File

@ -29,7 +29,6 @@
#include "internal.h" #include "internal.h"
#include "conf/virdomainobjlist.h" #include "conf/virdomainobjlist.h"
#include "intprops.h"
#include "viralloc.h" #include "viralloc.h"
#include "virmacaddr.h" #include "virmacaddr.h"
#include "virxml.h" #include "virxml.h"
@ -1964,7 +1963,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd)
bool ret = false; bool ret = false;
virshDomainListPtr list = NULL; virshDomainListPtr list = NULL;
virDomainPtr dom; virDomainPtr dom;
char id_buf[INT_BUFSIZE_BOUND(unsigned int)]; char id_buf[VIR_INT64_STR_BUFLEN];
unsigned int id; unsigned int id;
unsigned int flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE; unsigned int flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE;
vshTablePtr table = NULL; vshTablePtr table = NULL;

View File

@ -33,11 +33,12 @@
* so don't introduce a link time dep, which we must avoid * so don't introduce a link time dep, which we must avoid
*/ */
#include "gnulib/lib/configmake.h" #include "gnulib/lib/configmake.h"
#include "gnulib/lib/intprops.h"
#define VIR_INT64_STR_BUFLEN 21
int main(int argc, char **argv) { int main(int argc, char **argv) {
char uidstr[INT_BUFSIZE_BOUND(uid_t)]; char uidstr[VIR_INT64_STR_BUFLEN];
char gidstr[INT_BUFSIZE_BOUND(gid_t)]; char gidstr[VIR_INT64_STR_BUFLEN];
const char * newargv[6]; const char * newargv[6];
size_t nargs = 0; size_t nargs = 0;
char *newenv[] = { char *newenv[] = {