diff --git a/js/src/jsapi-tests/testPrintf.cpp b/js/src/jsapi-tests/testPrintf.cpp index 603a6a872529..332d0d85cdd9 100644 --- a/js/src/jsapi-tests/testPrintf.cpp +++ b/js/src/jsapi-tests/testPrintf.cpp @@ -25,7 +25,11 @@ static bool MOZ_FORMAT_PRINTF(2, 3) return output && !strcmp(output.get(), expect); } -static const char* zero() { return nullptr; } +static const char* zero() { + // gcc 9 is altogether too clever about detecting that this will always + // return nullptr. Do not replace 0x10 with 0x1; it will no longer work. + return uintptr_t(&zero) == 0x10 ? "never happens" : nullptr; +} BEGIN_TEST(testPrintf) { CHECK(print_one("23", "%d", 23)); diff --git a/js/src/shell/OSObject.cpp b/js/src/shell/OSObject.cpp index b4eb635ef581..fc52922aacbb 100644 --- a/js/src/shell/OSObject.cpp +++ b/js/src/shell/OSObject.cpp @@ -141,8 +141,8 @@ JSString* ResolvePath(JSContext* cx, HandleString filenameStr, // The docs say it can return EINVAL, but the compiler says it's void _splitpath(scriptFilename.get(), nullptr, buffer, nullptr, nullptr); #else - strncpy(buffer, scriptFilename.get(), PATH_MAX + 1); - if (buffer[PATH_MAX] != '\0') { + strncpy(buffer, scriptFilename.get(), PATH_MAX); + if (buffer[PATH_MAX - 1] != '\0') { return nullptr; } diff --git a/mfbt/DefineEnum.h b/mfbt/DefineEnum.h index d414a90d9bb6..afcff10e5212 100644 --- a/mfbt/DefineEnum.h +++ b/mfbt/DefineEnum.h @@ -90,8 +90,8 @@ /* * A helper macro for asserting that an enumerator does not have an initializer. * - * The static_assert and the comparison to 0 are just scaffolding; the - * important part is forming the expression |aEnumName::aEnumeratorDecl|. + * The static_assert and the comparison are just scaffolding; the important + * part is forming the expression |aEnumName::aEnumeratorDecl|. * * If |aEnumeratorDecl| is just the enumerator name without an identifier, * this expression compiles fine. However, if |aEnumeratorDecl| includes an @@ -99,19 +99,20 @@ * compile in expression context, since |eEnumerator| is not an lvalue. * * (The static_assert itself should always pass in the absence of the above - * error, since you can't get a negative enumerator value without having - * an initializer somewhere. It just provides a place to put the expression - * we want to form.) + * error, since turning on a bit can only increase an integer value. It just + * provides a place to put the expression we want to form.) */ + #define MOZ_ASSERT_ENUMERATOR_HAS_NO_INITIALIZER(aEnumName, aEnumeratorDecl) \ static_assert( \ - (aEnumName::aEnumeratorDecl) >= aEnumName(0), \ + int(aEnumName::aEnumeratorDecl) <= \ + (int(aEnumName::aEnumeratorDecl) | 1), \ "MOZ_DEFINE_ENUM does not allow enumerators to have initializers"); #define MOZ_DEFINE_ENUM_IMPL(aEnumName, aClassSpec, aBaseSpec, aEnumerators) \ enum aClassSpec aEnumName aBaseSpec{MOZ_UNWRAP_ARGS aEnumerators}; \ constexpr size_t k##aEnumName##Count = MOZ_ARG_COUNT aEnumerators; \ - constexpr aEnumName k##Highest##aEnumName = \ + constexpr aEnumName kHighest##aEnumName = \ aEnumName(k##aEnumName##Count - 1); \ MOZ_FOR_EACH(MOZ_ASSERT_ENUMERATOR_HAS_NO_INITIALIZER, (aEnumName, ), \ aEnumerators) @@ -132,7 +133,7 @@ aEnumerators) \ enum aClassSpec aEnumName aBaseSpec{MOZ_UNWRAP_ARGS aEnumerators}; \ constexpr static size_t s##aEnumName##Count = MOZ_ARG_COUNT aEnumerators; \ - constexpr static aEnumName s##Highest##aEnumName = \ + constexpr static aEnumName sHighest##aEnumName = \ aEnumName(s##aEnumName##Count - 1); \ MOZ_FOR_EACH(MOZ_ASSERT_ENUMERATOR_HAS_NO_INITIALIZER, (aEnumName, ), \ aEnumerators)