From: John Wolfe Date: Sun, 21 Aug 2022 14:56:49 +0000 (-0700) Subject: Common header file change not applicable to open-vm-tools. X-Git-Tag: stable-12.1.0~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=08cac55b2a37fac30adfb090748ca2b96c3256db;p=thirdparty%2Fopen-vm-tools.git Common header file change not applicable to open-vm-tools. --- diff --git a/open-vm-tools/lib/include/vm_atomic.h b/open-vm-tools/lib/include/vm_atomic.h index 4cdddf336..a1ab55dcd 100644 --- a/open-vm-tools/lib/include/vm_atomic.h +++ b/open-vm-tools/lib/include/vm_atomic.h @@ -1521,7 +1521,21 @@ Atomic_Sub32(Atomic_uint32 *var, // IN/OUT ); #endif /* VM_X86_ANY */ #elif defined _MSC_VER - _InterlockedExchangeAdd((long *)&var->value, -(long)val); + /* + * Microsoft warning C4146, enabled by the /sdl option for + * additional security checks, objects to `-val' when val is + * unsigned, even though that is always well-defined by C and has + * exactly the semantics we want, namely negation modulo 2^32. + * (The signed version, in contrast, has undefined behaviour at + * some inputs.) + * + * https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-2-c4146?view=msvc-170 + * https://docs.microsoft.com/en-us/cpp/build/reference/sdl-enable-additional-security-checks?view=msvc-170 + */ +# pragma warning(push) +# pragma warning(disable: 4146) + _InterlockedExchangeAdd((long *)&var->value, (long)-val); +# pragma warning(pop) #else #error No compiler defined for Atomic_Sub #endif @@ -2229,7 +2243,25 @@ Atomic_ReadSub64(Atomic_uint64 *var, // IN/OUT #if defined __GNUC__ && defined VM_ARM_64 return _VMATOM_X(ROP, 64, TRUE, &var->value, sub, val); #else - return Atomic_ReadAdd64(var, (uint64)-(int64)val); +# ifdef _MSC_VER + /* + * Microsoft warning C4146, enabled by the /sdl option for + * additional security checks, objects to `-val' when val is + * unsigned, even though that is always well-defined by C and has + * exactly the semantics we want, namely negation modulo 2^64. + * (The signed version, in contrast, has undefined behaviour at + * some inputs.) + * + * https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-2-c4146?view=msvc-170 + * https://docs.microsoft.com/en-us/cpp/build/reference/sdl-enable-additional-security-checks?view=msvc-170 + */ +# pragma warning(push) +# pragma warning(disable: 4146) +# endif + return Atomic_ReadAdd64(var, -val); +# ifdef _MSC_VER +# pragma warning(pop) +# endif #endif }