提交 f018fbac 编写于 作者: D Daniel P. Berrangé

src: remove use of the INT_MULTIPLY_OVERFLOW macro

The GLib g_size_checked_mul() function is not quite the
same signature, and gives compiler warnings due to not
correctly casting from gsize to guint64/32. Implementing
a replacement for INT_MULTIPLY_OVERFLOW is easy enough
to do ourselves.
Reviewed-by: NPavel Hrdina <phrdina@redhat.com>
Signed-off-by: NDaniel P. Berrangé <berrange@redhat.com>
上级 117353f9
...@@ -1606,20 +1606,6 @@ sc_prohibit_strings_without_use: ...@@ -1606,20 +1606,6 @@ sc_prohibit_strings_without_use:
re='\<(strn?casecmp|ffs(ll)?)\>' \ re='\<(strn?casecmp|ffs(ll)?)\>' \
$(_sc_header_without_use) $(_sc_header_without_use)
# Extract the raw list of symbol names with this:
gl_extract_define_simple = \
/^\# *define ([A-Z]\w+)\(/ and print $$1
# Filter out duplicates and convert to a space-separated list:
_intprops_names = \
$(shell f=$(gnulib_dir)/lib/intprops.h; \
perl -lne '$(gl_extract_define_simple)' $$f | sort -u | tr '\n' ' ')
# Remove trailing space and convert to a regular expression:
_intprops_syms_re = $(subst $(_sp),|,$(strip $(_intprops_names)))
# Prohibit the inclusion of intprops.h without an actual use.
sc_prohibit_intprops_without_use:
@h='intprops.h' \
re='\<($(_intprops_syms_re)) *\(' \
$(_sc_header_without_use)
_stddef_syms_re = NULL|offsetof|ptrdiff_t|size_t|wchar_t _stddef_syms_re = NULL|offsetof|ptrdiff_t|size_t|wchar_t
# Prohibit the inclusion of stddef.h without an actual use. # Prohibit the inclusion of stddef.h without an actual use.
...@@ -1714,7 +1700,6 @@ sc_prohibit_defined_have_decl_tests: ...@@ -1714,7 +1700,6 @@ sc_prohibit_defined_have_decl_tests:
# ================================================================== # ==================================================================
gl_other_headers_ ?= \ gl_other_headers_ ?= \
intprops.h \
openat.h \ openat.h \
stat-macros.h stat-macros.h
......
...@@ -38,6 +38,8 @@ ...@@ -38,6 +38,8 @@
# define sa_assert(expr) /* empty */ # define sa_assert(expr) /* empty */
#endif #endif
#define VIR_INT_MULTIPLY_OVERFLOW(a,b) (G_UNLIKELY ((b) > 0 && (a) > G_MAXINT / (b)))
/* The library itself is allowed to use deprecated functions / /* The library itself is allowed to use deprecated functions /
* variables, so effectively undefine the deprecated attribute * variables, so effectively undefine the deprecated attribute
* which would otherwise be defined in libvirt.h. * which would otherwise be defined in libvirt.h.
......
...@@ -21,8 +21,6 @@ ...@@ -21,8 +21,6 @@
#include <config.h> #include <config.h>
#include <sys/stat.h> #include <sys/stat.h>
#include "intprops.h"
#include "datatypes.h" #include "datatypes.h"
#include "viralloc.h" #include "viralloc.h"
#include "virfile.h" #include "virfile.h"
...@@ -7302,7 +7300,7 @@ virDomainGetVcpuPinInfo(virDomainPtr domain, int ncpumaps, ...@@ -7302,7 +7300,7 @@ virDomainGetVcpuPinInfo(virDomainPtr domain, int ncpumaps,
virCheckPositiveArgGoto(ncpumaps, error); virCheckPositiveArgGoto(ncpumaps, error);
virCheckPositiveArgGoto(maplen, error); virCheckPositiveArgGoto(maplen, error);
if (INT_MULTIPLY_OVERFLOW(ncpumaps, maplen)) { if (VIR_INT_MULTIPLY_OVERFLOW(ncpumaps, maplen)) {
virReportError(VIR_ERR_OVERFLOW, _("input too large: %d * %d"), virReportError(VIR_ERR_OVERFLOW, _("input too large: %d * %d"),
ncpumaps, maplen); ncpumaps, maplen);
goto error; goto error;
...@@ -7503,7 +7501,7 @@ virDomainGetVcpus(virDomainPtr domain, virVcpuInfoPtr info, int maxinfo, ...@@ -7503,7 +7501,7 @@ virDomainGetVcpus(virDomainPtr domain, virVcpuInfoPtr info, int maxinfo,
else else
virCheckZeroArgGoto(maplen, error); virCheckZeroArgGoto(maplen, error);
if (cpumaps && INT_MULTIPLY_OVERFLOW(maxinfo, maplen)) { if (cpumaps && VIR_INT_MULTIPLY_OVERFLOW(maxinfo, maplen)) {
virReportError(VIR_ERR_OVERFLOW, _("input too large: %d * %d"), virReportError(VIR_ERR_OVERFLOW, _("input too large: %d * %d"),
maxinfo, maplen); maxinfo, maplen);
goto error; goto error;
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#include "remote_daemon_stream.h" #include "remote_daemon_stream.h"
#include "viruuid.h" #include "viruuid.h"
#include "vircommand.h" #include "vircommand.h"
#include "intprops.h"
#include "virnetserverservice.h" #include "virnetserverservice.h"
#include "virnetserver.h" #include "virnetserver.h"
#include "virfile.h" #include "virfile.h"
...@@ -2755,7 +2754,7 @@ remoteDispatchDomainGetVcpuPinInfo(virNetServerPtr server G_GNUC_UNUSED, ...@@ -2755,7 +2754,7 @@ remoteDispatchDomainGetVcpuPinInfo(virNetServerPtr server G_GNUC_UNUSED,
goto cleanup; goto cleanup;
} }
if (INT_MULTIPLY_OVERFLOW(args->ncpumaps, args->maplen) || if (VIR_INT_MULTIPLY_OVERFLOW(args->ncpumaps, args->maplen) ||
args->ncpumaps * args->maplen > REMOTE_CPUMAPS_MAX) { args->ncpumaps * args->maplen > REMOTE_CPUMAPS_MAX) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("maxinfo * maplen > REMOTE_CPUMAPS_MAX")); virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("maxinfo * maplen > REMOTE_CPUMAPS_MAX"));
goto cleanup; goto cleanup;
...@@ -2898,7 +2897,7 @@ remoteDispatchDomainGetVcpus(virNetServerPtr server G_GNUC_UNUSED, ...@@ -2898,7 +2897,7 @@ remoteDispatchDomainGetVcpus(virNetServerPtr server G_GNUC_UNUSED,
goto cleanup; goto cleanup;
} }
if (INT_MULTIPLY_OVERFLOW(args->maxinfo, args->maplen) || if (VIR_INT_MULTIPLY_OVERFLOW(args->maxinfo, args->maplen) ||
args->maxinfo * args->maplen > REMOTE_CPUMAPS_MAX) { args->maxinfo * args->maplen > REMOTE_CPUMAPS_MAX) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("maxinfo * maplen > REMOTE_CPUMAPS_MAX")); virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("maxinfo * maplen > REMOTE_CPUMAPS_MAX"));
goto cleanup; goto cleanup;
......
...@@ -43,7 +43,6 @@ ...@@ -43,7 +43,6 @@
#include "viralloc.h" #include "viralloc.h"
#include "virfile.h" #include "virfile.h"
#include "vircommand.h" #include "vircommand.h"
#include "intprops.h"
#include "virtypedparam.h" #include "virtypedparam.h"
#include "viruri.h" #include "viruri.h"
#include "virauth.h" #include "virauth.h"
...@@ -2236,7 +2235,7 @@ remoteDomainGetVcpuPinInfo(virDomainPtr domain, ...@@ -2236,7 +2235,7 @@ remoteDomainGetVcpuPinInfo(virDomainPtr domain,
goto done; goto done;
} }
if (INT_MULTIPLY_OVERFLOW(ncpumaps, maplen) || if (VIR_INT_MULTIPLY_OVERFLOW(ncpumaps, maplen) ||
ncpumaps * maplen > REMOTE_CPUMAPS_MAX) { ncpumaps * maplen > REMOTE_CPUMAPS_MAX) {
virReportError(VIR_ERR_RPC, virReportError(VIR_ERR_RPC,
_("vCPU map buffer length exceeds maximum: %d > %d"), _("vCPU map buffer length exceeds maximum: %d > %d"),
...@@ -2405,7 +2404,7 @@ remoteDomainGetVcpus(virDomainPtr domain, ...@@ -2405,7 +2404,7 @@ remoteDomainGetVcpus(virDomainPtr domain,
maxinfo, REMOTE_VCPUINFO_MAX); maxinfo, REMOTE_VCPUINFO_MAX);
goto done; goto done;
} }
if (INT_MULTIPLY_OVERFLOW(maxinfo, maplen) || if (VIR_INT_MULTIPLY_OVERFLOW(maxinfo, maplen) ||
maxinfo * maplen > REMOTE_CPUMAPS_MAX) { maxinfo * maplen > REMOTE_CPUMAPS_MAX) {
virReportError(VIR_ERR_RPC, virReportError(VIR_ERR_RPC,
_("vCPU map buffer length exceeds maximum: %d > %d"), _("vCPU map buffer length exceeds maximum: %d > %d"),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册