Bug 785918 - Part 1: Replace PR_ARRAY_SIZE() with mozilla::ArrayLength() and MOZ_ARRAY_LENGTH(). r=ehsan

This commit is contained in:
Chris Peterson 2013-01-05 23:37:25 -08:00
parent 48a3a12ac9
commit d2b4e410e5
4 changed files with 25 additions and 12 deletions

View File

@ -5,7 +5,9 @@
#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"
@ -106,7 +108,7 @@ typedef enum {
/* 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",
@ -170,7 +172,8 @@ static const char *cc_feature_names[] = {
/* 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
@ -250,7 +253,7 @@ typedef enum cc_msgs_t_ {
} cc_msgs_t;
#ifdef __CC_MESSAGES_STRINGS__
static const char *cc_msg_names[] = {
static const char *const cc_msg_names[] = {
"SETUP",
"SETUP_ACK",
"PROCEEDING",
@ -292,7 +295,8 @@ static const char *cc_msg_names[] = {
/* 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__

View File

@ -269,4 +269,11 @@ ArrayEnd(T (&arr)[N])
#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_ */

View File

@ -395,7 +395,7 @@ nsStrictTransportSecurityService::GetPreloadListEntry(const char *aHost)
if (mUsePreloadList && currentTime < gPreloadListExpirationTime) {
return (const nsSTSPreload *) bsearch(aHost,
kSTSPreloadList,
PR_ARRAY_SIZE(kSTSPreloadList),
mozilla::ArrayLength(kSTSPreloadList),
sizeof(nsSTSPreload),
STSPreloadCompare);
}

View File

@ -22,6 +22,8 @@
#include "keyhi.h"
#include "cryptohi.h"
#include <limits.h>
using namespace mozilla;
namespace {
@ -424,15 +426,15 @@ GenerateDSAKeyPair(PK11SlotInfo * slot,
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,