diff options
author | Gil <mcg@google.com> | 2018-05-22 13:21:08 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-22 13:21:08 -0700 |
commit | d439bbccd4b90583a89d209d2cc81308aabca8ac (patch) | |
tree | 13fb14cc905f667e1470bcc14a3c84dfb6a7a109 /Firestore/core/src/firebase/firestore/nanopb | |
parent | 476be0ba2ba8340296a5b5b05f27f3ded4bd6c72 (diff) |
Add a HARD_ASSERT C++ assertion macro (#1304)
* Add HARD_ASSERT
* Use HARD_ASSERT
* Remove FIREBASE_ASSERT
* Remove StringPrintf
Diffstat (limited to 'Firestore/core/src/firebase/firestore/nanopb')
-rw-r--r-- | Firestore/core/src/firebase/firestore/nanopb/reader.cc | 4 | ||||
-rw-r--r-- | Firestore/core/src/firebase/firestore/nanopb/reader.h | 4 | ||||
-rw-r--r-- | Firestore/core/src/firebase/firestore/nanopb/writer.cc | 16 |
3 files changed, 11 insertions, 13 deletions
diff --git a/Firestore/core/src/firebase/firestore/nanopb/reader.cc b/Firestore/core/src/firebase/firestore/nanopb/reader.cc index 86e38ac..7a12900 100644 --- a/Firestore/core/src/firebase/firestore/nanopb/reader.cc +++ b/Firestore/core/src/firebase/firestore/nanopb/reader.cc @@ -41,7 +41,7 @@ Tag Reader::ReadTag() { } // nanopb code always returns a false status when setting eof. - FIREBASE_ASSERT_MESSAGE(!eof, "nanopb set both ok status and eof to true"); + HARD_ASSERT(!eof, "nanopb set both ok status and eof to true"); return tag; } @@ -127,7 +127,7 @@ std::string Reader::ReadString() { // check within pb_close_string_substream. Unfortunately, that's not present // in the current version (0.38). We'll make a stronger assertion and check // to make sure there *are* no remaining characters in the substream. - FIREBASE_ASSERT_MESSAGE( + HARD_ASSERT( substream.bytes_left == 0, "Bytes remaining in substream after supposedly reading all of them."); diff --git a/Firestore/core/src/firebase/firestore/nanopb/reader.h b/Firestore/core/src/firebase/firestore/nanopb/reader.h index 093e20b..930211a 100644 --- a/Firestore/core/src/firebase/firestore/nanopb/reader.h +++ b/Firestore/core/src/firebase/firestore/nanopb/reader.h @@ -26,7 +26,7 @@ #include "Firestore/core/include/firebase/firestore/firestore_errors.h" #include "Firestore/core/src/firebase/firestore/nanopb/tag.h" -#include "Firestore/core/src/firebase/firestore/util/firebase_assert.h" +#include "Firestore/core/src/firebase/firestore/util/hard_assert.h" #include "Firestore/core/src/firebase/firestore/util/status.h" namespace firebase { @@ -159,7 +159,7 @@ T Reader::ReadNestedMessage(const std::function<T(Reader*)>& read_message_fn) { // check within pb_close_string_substream. Unfortunately, that's not present // in the current version (0.38). We'll make a stronger assertion and check // to make sure there *are* no remaining characters in the substream. - FIREBASE_ASSERT_MESSAGE( + HARD_ASSERT( substream.bytes_left() == 0, "Bytes remaining in substream after supposedly reading all of them."); diff --git a/Firestore/core/src/firebase/firestore/nanopb/writer.cc b/Firestore/core/src/firebase/firestore/nanopb/writer.cc index cbee989..c3ffaac 100644 --- a/Firestore/core/src/firebase/firestore/nanopb/writer.cc +++ b/Firestore/core/src/firebase/firestore/nanopb/writer.cc @@ -58,7 +58,7 @@ void Writer::WriteTag(Tag tag) { if (!status_.ok()) return; if (!pb_encode_tag(&stream_, tag.wire_type, tag.field_number)) { - FIREBASE_ASSERT_MESSAGE(false, PB_GET_ERROR(&stream_)); + HARD_FAIL(PB_GET_ERROR(&stream_)); } } @@ -67,7 +67,7 @@ void Writer::WriteNanopbMessage(const pb_field_t fields[], if (!status_.ok()) return; if (!pb_encode(&stream_, fields, src_struct)) { - FIREBASE_ASSERT_MESSAGE(false, PB_GET_ERROR(&stream_)); + HARD_FAIL(PB_GET_ERROR(&stream_)); } } @@ -79,7 +79,7 @@ void Writer::WriteVarint(uint64_t value) { if (!status_.ok()) return; if (!pb_encode_varint(&stream_, value)) { - FIREBASE_ASSERT_MESSAGE(false, PB_GET_ERROR(&stream_)); + HARD_FAIL(PB_GET_ERROR(&stream_)); } } @@ -101,7 +101,7 @@ void Writer::WriteString(const std::string& string_value) { if (!pb_encode_string( &stream_, reinterpret_cast<const pb_byte_t*>(string_value.c_str()), string_value.length())) { - FIREBASE_ASSERT_MESSAGE(false, PB_GET_ERROR(&stream_)); + HARD_FAIL(PB_GET_ERROR(&stream_)); } } @@ -126,15 +126,14 @@ void Writer::WriteNestedMessage( // fail since sizing streams don't actually have any buffer space.) if (stream_.callback == nullptr) { if (!pb_write(&stream_, nullptr, size)) { - FIREBASE_ASSERT_MESSAGE(false, PB_GET_ERROR(&stream_)); + HARD_FAIL(PB_GET_ERROR(&stream_)); } return; } // Ensure the output stream has enough space if (stream_.bytes_written + size > stream_.max_size) { - FIREBASE_ASSERT_MESSAGE( - false, + HARD_FAIL( "Insufficient space in the output stream to write the given message"); } @@ -155,8 +154,7 @@ void Writer::WriteNestedMessage( if (writer.bytes_written() != size) { // submsg size changed - FIREBASE_ASSERT_MESSAGE( - false, "Parsing the nested message twice yielded different sizes"); + HARD_FAIL("Parsing the nested message twice yielded different sizes"); } } |