Bug 1626772 - Fixes for gcc 9 warnings r=botond

Differential Revision: https://phabricator.services.mozilla.com/D69275

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Steve Fink 2020-04-10 20:40:03 +00:00
Родитель 4f03b7c3ce
Коммит 36169fa9e9
3 изменённых файлов: 16 добавлений и 11 удалений

Просмотреть файл

@ -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));

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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)