From 9a9654c4bdfeeab78b602a27615ab1845b7ba383 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Fri, 15 Apr 2016 17:44:00 +0530 Subject: [PATCH] Fix off-by-one in cross_sizeof and cross_alignment on MSVC --- mesonbuild/compilers.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py index 8dee468a7..e9a798d59 100644 --- a/mesonbuild/compilers.py +++ b/mesonbuild/compilers.py @@ -596,6 +596,10 @@ int temparray[%d-sizeof(%s)]; for i in range(1, 1024): code = templ % (prefix, i, element) if self.compiles(code, extra_args): + if self.id == 'msvc': + # MSVC refuses to construct an array of zero size, so + # the test only succeeds when i is sizeof(element) + 1 + return i - 1 return i raise EnvironmentException('Cross checking sizeof overflowed.') @@ -633,6 +637,10 @@ int testarray[%d-offsetof(struct tmp, target)]; for i in range(1, 1024): code = templ % (typename, i) if self.compiles(code, extra_args): + if self.id == 'msvc': + # MSVC refuses to construct an array of zero size, so + # the test only succeeds when i is sizeof(element) + 1 + return i - 1 return i raise EnvironmentException('Cross checking offsetof overflowed.')