Bug 785918 - Part 1: Replace PR_ARRAY_SIZE() with mozilla::ArrayLength() and MOZ_ARRAY_LENGTH(). r=ehsan
--- a/media/webrtc/signaling/src/sipcc/core/includes/ccapi.h
+++ b/media/webrtc/signaling/src/sipcc/core/includes/ccapi.h
@@ -1,16 +1,18 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef _CCAPI_H_
#define _CCAPI_H_
-#include "prtypes.h"
+#include "mozilla/Assertions.h"
+#include "mozilla/Util.h"
+
#include "cpr_types.h"
#include "cpr_memory.h"
#include "phone_types.h"
#include "string_lib.h"
#include "vcm.h"
#include "sdp.h"
#include "cc_constants.h"
@@ -101,17 +103,17 @@ typedef enum {
} group_cc_feature_t;
#define skNewCall CC_FEATURE_NEW_CALL
#define skConfrn CC_FEATURE_CONF
/* please update the following cc_feature_names whenever this feature list is changed */
#ifdef __CC_FEATURE_STRINGS__
-static const char *cc_feature_names[] = {
+static const char *const cc_feature_names[] = {
"NONE",
"HOLD",
"RESUME",
"OFFHOOK",
"NEW_CALL",
"REDIAL",
"ONHOOK",
"KEYPRESS",
@@ -165,17 +167,18 @@ static const char *cc_feature_names[] =
"REMOVESTREAM",
"ADDICECANDIDATE",
"MAX"
};
/* This checks at compile-time that the cc_feature_names list
* is the same size as the cc_group_feature_t enum
*/
-PR_STATIC_ASSERT(PR_ARRAY_SIZE(cc_feature_names) == CC_FEATURE_MAX + 1);
+MOZ_STATIC_ASSERT(MOZ_ARRAY_LENGTH(cc_feature_names) == CC_FEATURE_MAX + 1,
+ "cc_feature_names size == cc_group_feature_t size?");
#endif
/*
* Constants
*/
#define CC_MAX_DIALSTRING_LEN (512)
#define CC_MAX_MEDIA_TYPES (15)
@@ -245,17 +248,17 @@ typedef enum cc_msgs_t_ {
CC_MSG_NOTIFY,
CC_MSG_FAILOVER_FALLBACK,
CC_MSG_INFO,
/* update the following strings table if this is changed */
CC_MSG_MAX
} cc_msgs_t;
#ifdef __CC_MESSAGES_STRINGS__
-static const char *cc_msg_names[] = {
+static const char *const cc_msg_names[] = {
"SETUP",
"SETUP_ACK",
"PROCEEDING",
"ALERTING",
"CONNECTED",
"CONNECTED_ACK",
"RELEASE",
"RELEASE_COMPLETE",
@@ -287,17 +290,18 @@ static const char *cc_msg_names[] = {
"FAILOVER_FALLBACK",
"INFO",
"INVALID",
};
/* This checks at compile-time that the cc_msg_names list
* is the same size as the cc_msgs_t enum
*/
-PR_STATIC_ASSERT(PR_ARRAY_SIZE(cc_msg_names) == CC_MSG_MAX + 1);
+MOZ_STATIC_ASSERT(MOZ_ARRAY_LENGTH(cc_msg_names) == CC_MSG_MAX + 1,
+ "cc_msg_names size == cc_msgs_t size?");
#endif //__CC_MESSAGES_STRINGS__
typedef enum cc_srcs_t_ {
CC_SRC_MIN = -1,
CC_SRC_GSM,
CC_SRC_UI,
CC_SRC_SIP,
--- a/mfbt/Util.h
+++ b/mfbt/Util.h
@@ -264,9 +264,16 @@ ArrayEnd(T (&arr)[N])
{
return arr + ArrayLength(arr);
}
} /* namespace mozilla */
#endif /* __cplusplus */
+/*
+ * MOZ_ARRAY_LENGTH() is an alternative to mozilla::ArrayLength() for C files
+ * that can't use C++ template functions and for MOZ_STATIC_ASSERT() calls that
+ * can't call ArrayLength() when it is not a C++11 constexpr function.
+ */
+#define MOZ_ARRAY_LENGTH(array) (sizeof(array)/sizeof((array)[0]))
+
#endif /* mozilla_Util_h_ */
--- a/security/manager/boot/src/nsStrictTransportSecurityService.cpp
+++ b/security/manager/boot/src/nsStrictTransportSecurityService.cpp
@@ -390,17 +390,17 @@ nsStrictTransportSecurityService::GetPre
&timeOffset);
if (NS_SUCCEEDED(rv)) {
currentTime += (PRTime(timeOffset) * PR_USEC_PER_SEC);
}
if (mUsePreloadList && currentTime < gPreloadListExpirationTime) {
return (const nsSTSPreload *) bsearch(aHost,
kSTSPreloadList,
- PR_ARRAY_SIZE(kSTSPreloadList),
+ mozilla::ArrayLength(kSTSPreloadList),
sizeof(nsSTSPreload),
STSPreloadCompare);
}
return nullptr;
}
NS_IMETHODIMP
--- a/toolkit/identity/IdentityCryptoService.cpp
+++ b/toolkit/identity/IdentityCryptoService.cpp
@@ -17,16 +17,18 @@
#include "nss.h"
#include "pk11pub.h"
#include "secmod.h"
#include "secerr.h"
#include "keyhi.h"
#include "cryptohi.h"
+#include <limits.h>
+
using namespace mozilla;
namespace {
void
HexEncode(const SECItem * it, nsACString & result)
{
const char * digits = "0123456789ABCDEF";
@@ -419,25 +421,25 @@ GenerateDSAKeyPair(PK11SlotInfo * slot,
0x10,0xB9,0x6A,0xFB,0x17,0xC7,0xA0,0x32,0x59,0x32,0x9E,0x48,
0x29,0xB0,0xD0,0x3B,0xBC,0x78,0x96,0xB1,0x5B,0x4A,0xDE,0x53,
0xE1,0x30,0x85,0x8C,0xC3,0x4D,0x96,0x26,0x9A,0xA8,0x90,0x41,
0xF4,0x09,0x13,0x6C,0x72,0x42,0xA3,0x88,0x95,0xC9,0xD5,0xBC,
0xCA,0xD4,0xF3,0x89,0xAF,0x1D,0x7A,0x4B,0xD1,0x39,0x8B,0xD0,
0x72,0xDF,0xFA,0x89,0x62,0x33,0x39,0x7A
};
- MOZ_STATIC_ASSERT(PR_ARRAY_SIZE(P) == 1024 / PR_BITS_PER_BYTE, "bad DSA P");
- MOZ_STATIC_ASSERT(PR_ARRAY_SIZE(Q) == 160 / PR_BITS_PER_BYTE, "bad DSA Q");
- MOZ_STATIC_ASSERT(PR_ARRAY_SIZE(G) == 1024 / PR_BITS_PER_BYTE, "bad DSA G");
+ MOZ_STATIC_ASSERT(MOZ_ARRAY_LENGTH(P) == 1024 / CHAR_BIT, "bad DSA P");
+ MOZ_STATIC_ASSERT(MOZ_ARRAY_LENGTH(Q) == 160 / CHAR_BIT, "bad DSA Q");
+ MOZ_STATIC_ASSERT(MOZ_ARRAY_LENGTH(G) == 1024 / CHAR_BIT, "bad DSA G");
PQGParams pqgParams = {
NULL /*arena*/,
- { siBuffer, P, PR_ARRAY_SIZE(P) },
- { siBuffer, Q, PR_ARRAY_SIZE(Q) },
- { siBuffer, G, PR_ARRAY_SIZE(G) }
+ { siBuffer, P, static_cast<unsigned int>(mozilla::ArrayLength(P)) },
+ { siBuffer, Q, static_cast<unsigned int>(mozilla::ArrayLength(Q)) },
+ { siBuffer, G, static_cast<unsigned int>(mozilla::ArrayLength(G)) }
};
return GenerateKeyPair(slot, privateKey, publicKey, CKM_DSA_KEY_PAIR_GEN,
&pqgParams);
}
NS_IMETHODIMP
KeyGenRunnable::Run()