diff --git a/xpcom/glue/nsISupportsImpl.cpp b/xpcom/glue/nsISupportsImpl.cpp index 4f0170c5d65..75198aacce6 100644 --- a/xpcom/glue/nsISupportsImpl.cpp +++ b/xpcom/glue/nsISupportsImpl.cpp @@ -8,7 +8,7 @@ nsresult NS_FASTCALL NS_TableDrivenQI(void* aThis, const QITableEntry* entries, REFNSIID aIID, void **aInstancePtr) { - while (entries->iid) { + do { if (aIID.Equals(*entries->iid)) { nsISupports* r = reinterpret_cast @@ -19,7 +19,7 @@ NS_TableDrivenQI(void* aThis, const QITableEntry* entries, } ++entries; - } + } while (entries->iid); *aInstancePtr = nullptr; return NS_ERROR_NO_INTERFACE; diff --git a/xpcom/glue/nsISupportsImpl.h b/xpcom/glue/nsISupportsImpl.h index bd09a65f171..27abc32a1cb 100644 --- a/xpcom/glue/nsISupportsImpl.h +++ b/xpcom/glue/nsISupportsImpl.h @@ -609,8 +609,15 @@ NS_IMETHODIMP _class::QueryInterface(REFNSIID aIID, void** aInstancePtr) \ reinterpret_cast((_class*) 0x1000)) \ }, +/* + * XXX: we want to use mozilla::ArrayLength (or equivalent, + * MOZ_ARRAY_LENGTH) in this condition, but some versions of GCC don't + * see that the static_assert condition is actually constant in those + * cases, even with constexpr support (?). + */ #define NS_INTERFACE_TABLE_END_WITH_PTR(_ptr) \ { nullptr, 0 } }; \ + static_assert((sizeof(table)/sizeof(table[0])) > 1, "need at least 1 interface"); \ rv = NS_TableDrivenQI(static_cast(_ptr), \ table, aIID, aInstancePtr);