Skip to content

Commit

Permalink
Bug 1048070, Part 2: Remove uses of PR_NOT_REACHED and PR_ARRAY_SIZE …
Browse files Browse the repository at this point in the history
…in mozilla::pkix, r=keeeler

--HG--
extra : rebase_source : d373a7526c1048770bed8bacb7e14c8f10e832cb
  • Loading branch information
briansmith committed Aug 4, 2014
1 parent 3d6211a commit 78c73d9
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 24 deletions.
4 changes: 1 addition & 3 deletions lib/mozpkix/include/pkix/Input.h
Expand Up @@ -29,7 +29,6 @@

#include "pkix/nullptr.h"
#include "pkix/Result.h"
#include "prlog.h"
#include "stdint.h"

namespace mozilla { namespace pkix {
Expand Down Expand Up @@ -283,8 +282,7 @@ class Reader
Result GetInput(const Mark& mark, /*out*/ Input& item)
{
if (&mark.input != this || mark.mark > input) {
PR_NOT_REACHED("invalid mark");
return Result::FATAL_ERROR_INVALID_ARGS;
return NotReached("invalid mark", Result::FATAL_ERROR_INVALID_ARGS);
}
return item.Init(mark.mark, static_cast<uint16_t>(input - mark.mark));
}
Expand Down
9 changes: 9 additions & 0 deletions lib/mozpkix/include/pkix/Result.h
Expand Up @@ -25,6 +25,8 @@
#ifndef mozilla_pkix__Result_h
#define mozilla_pkix__Result_h

#include <cassert>

#include "pkix/enumclass.h"

namespace mozilla { namespace pkix {
Expand Down Expand Up @@ -103,6 +105,13 @@ IsFatalError(Result rv)
return static_cast<unsigned int>(rv) & FATAL_ERROR_FLAG;
}

inline Result
NotReached(const char* /*explanation*/, Result result)
{
assert(false);
return result;
}

} } // namespace mozilla::pkix

#endif // mozilla_pkix__Result_h
7 changes: 3 additions & 4 deletions lib/mozpkix/lib/pkixbuild.cpp
Expand Up @@ -97,8 +97,8 @@ PathBuildingStep::RecordResult(Result newResult, /*out*/ bool& keepGoing)

if (resultWasSet) {
if (result == Success) {
PR_NOT_REACHED("RecordResult called after finding a chain");
return Result::FATAL_ERROR_INVALID_STATE;
return NotReached("RecordResult called after finding a chain",
Result::FATAL_ERROR_INVALID_STATE);
}
// If every potential issuer has the same problem (e.g. expired) and/or if
// there is only one bad potential issuer, then return a more specific
Expand Down Expand Up @@ -240,8 +240,7 @@ BuildForward(TrustDomain& trustDomain,
for (const BackCert* cert = &subject; cert; cert = cert->childCert) {
rv = chain.Append(cert->GetDER());
if (rv != Success) {
PR_NOT_REACHED("NonOwningDERArray::SetItem failed.");
return rv;
return NotReached("NonOwningDERArray::SetItem failed.", rv);
}
}

Expand Down
12 changes: 6 additions & 6 deletions lib/mozpkix/lib/pkixcheck.cpp
Expand Up @@ -194,9 +194,9 @@ CertPolicyId::IsAnyPolicy() const {
if (this == &CertPolicyId::anyPolicy) {
return true;
}
return numBytes == PR_ARRAY_SIZE(::mozilla::pkix::anyPolicy) &&
return numBytes == sizeof(::mozilla::pkix::anyPolicy) &&
!memcmp(bytes, ::mozilla::pkix::anyPolicy,
PR_ARRAY_SIZE(::mozilla::pkix::anyPolicy));
sizeof(::mozilla::pkix::anyPolicy));
}

// certificatePolicies ::= SEQUENCE SIZE (1..MAX) OF PolicyInformation
Expand Down Expand Up @@ -524,12 +524,12 @@ MatchEKU(Reader& value, KeyPurposeId requiredEKU,
break;

case KeyPurposeId::anyExtendedKeyUsage:
PR_NOT_REACHED("anyExtendedKeyUsage should start with found==true");
return Result::FATAL_ERROR_LIBRARY_FAILURE;
return NotReached("anyExtendedKeyUsage should start with found==true",
Result::FATAL_ERROR_LIBRARY_FAILURE);

default:
PR_NOT_REACHED("unrecognized EKU");
return Result::FATAL_ERROR_LIBRARY_FAILURE;
return NotReached("unrecognized EKU",
Result::FATAL_ERROR_LIBRARY_FAILURE);
}
}

Expand Down
8 changes: 4 additions & 4 deletions lib/mozpkix/lib/pkixder.cpp
Expand Up @@ -418,8 +418,8 @@ TimeChoice(Reader& tagged, uint8_t expectedTag, /*out*/ Time& time)
}
yearHi = yearLo >= 50u ? 19u : 20u;
} else {
PR_NOT_REACHED("invalid tag given to TimeChoice");
return Result::ERROR_INVALID_TIME;
return NotReached("invalid tag given to TimeChoice",
Result::ERROR_INVALID_TIME);
}
unsigned int year = (yearHi * 100u) + yearLo;
if (year < 1970u) {
Expand Down Expand Up @@ -474,8 +474,8 @@ TimeChoice(Reader& tagged, uint8_t expectedTag, /*out*/ Time& time)
jul + aug + sep + oct + nov;
break;
default:
PR_NOT_REACHED("month already bounds-checked by ReadTwoDigits");
return Result::FATAL_ERROR_INVALID_STATE;
return NotReached("month already bounds-checked by ReadTwoDigits",
Result::FATAL_ERROR_INVALID_STATE);
}

unsigned int dayOfMonth;
Expand Down
2 changes: 0 additions & 2 deletions lib/mozpkix/lib/pkixder.h
Expand Up @@ -37,8 +37,6 @@
// they are able to do so; otherwise they fail with the input mark in an
// undefined state.

#include <cassert>

#include "pkix/Input.h"
#include "pkix/pkixtypes.h"

Expand Down
7 changes: 3 additions & 4 deletions lib/mozpkix/lib/pkixocsp.cpp
Expand Up @@ -323,8 +323,7 @@ VerifyEncodedOCSPResponse(TrustDomain& trustDomain, const struct CertID& certID,
return Result::ERROR_OCSP_UNKNOWN_CERT;
}

PR_NOT_REACHED("unknown CertStatus");
return Result::ERROR_OCSP_UNKNOWN_CERT;
return NotReached("unknown CertStatus", Result::ERROR_OCSP_UNKNOWN_CERT);
}

// OCSPResponse ::= SEQUENCE {
Expand Down Expand Up @@ -888,7 +887,7 @@ CreateEncodedOCSPRequest(TrustDomain& trustDomain, const struct CertID& certID,
+ 2 // requestList
+ 2 // Request
+ 2 // reqCert (CertID)
+ PR_ARRAY_SIZE(hashAlgorithm) // hashAlgorithm
+ sizeof(hashAlgorithm) // hashAlgorithm
+ 2 + hashLen // issuerNameHash
+ 2 + hashLen // issuerKeyHash
+ 2; // serialNumber (header)
Expand Down Expand Up @@ -918,7 +917,7 @@ CreateEncodedOCSPRequest(TrustDomain& trustDomain, const struct CertID& certID,
*d++ = 0x30; *d++ = totalLen - 10u; // reqCert (CertID SEQUENCE)

// reqCert.hashAlgorithm
for (size_t i = 0; i < PR_ARRAY_SIZE(hashAlgorithm); ++i) {
for (size_t i = 0; i < sizeof(hashAlgorithm); ++i) {
*d++ = hashAlgorithm[i];
}

Expand Down
2 changes: 1 addition & 1 deletion lib/mozpkix/test/gtest/pkixder_input_tests.cpp
Expand Up @@ -441,7 +441,7 @@ TEST_F(pkixder_input_tests, MarkAndGetInput)
ASSERT_TRUE(InputsAreEqual(expected, item));
}

// Cannot run this test on debug builds because of the PR_NOT_REACHED
// Cannot run this test on debug builds because of the NotReached
#ifndef DEBUG
TEST_F(pkixder_input_tests, MarkAndGetInputDifferentInput)
{
Expand Down

0 comments on commit 78c73d9

Please sign in to comment.