aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Bonné <brambonne@google.com>2020-10-26 14:20:10 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-10-26 14:20:10 +0000
commit6e3a18c57179721084d8eb325cb55fa4f74cc396 (patch)
tree78b1e8469b084dc55846ba8f23260bb04b5c0428
parent9877e02662394db2961130230067365fc78ac491 (diff)
parent843849541c44e4dc762f10749eb9d826b0e9f495 (diff)
downloadlibcppbor-6e3a18c57179721084d8eb325cb55fa4f74cc396.tar.gz
Merge "Add Trusty support to libcppbor." am: 843849541c
Original change: https://android-review.googlesource.com/c/platform/external/libcppbor/+/1466585 Change-Id: I015f75788d465f1e3b23525f745f9ee69425f01a
-rw-r--r--rules.mk29
-rw-r--r--src/cppbor.cpp10
-rw-r--r--src/cppbor_parse.cpp17
3 files changed, 46 insertions, 10 deletions
diff --git a/rules.mk b/rules.mk
new file mode 100644
index 0000000..739fe23
--- /dev/null
+++ b/rules.mk
@@ -0,0 +1,29 @@
+# Copyright (C) 2020 The Android Open Source Project.
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+# SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+# OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+# This file is not used in the Android build process! It's used only by Trusty.
+
+LOCAL_DIR := $(GET_LOCAL_DIR)
+
+MODULE := $(LOCAL_DIR)
+
+MODULE_CPPFLAGS := -std=c++17 -frtti
+
+MODULE_SRCS := \
+ $(LOCAL_DIR)/src/cppbor.cpp \
+ $(LOCAL_DIR)/src/cppbor_parse.cpp
+
+GLOBAL_INCLUDES += $(LOCAL_DIR)/include/cppbor/
+
+include make/module.mk \ No newline at end of file
diff --git a/src/cppbor.cpp b/src/cppbor.cpp
index 25c2da1..223a445 100644
--- a/src/cppbor.cpp
+++ b/src/cppbor.cpp
@@ -16,8 +16,12 @@
#include "cppbor.h"
-#define LOG_TAG "CppBor"
-#include <android-base/logging.h>
+#ifndef __TRUSTY__
+ #include <android-base/logging.h>
+ #define LOG_TAG "CppBor"
+#else
+ #define CHECK(x) (void)(x)
+#endif
namespace cppbor {
@@ -129,7 +133,7 @@ bool Item::operator==(const Item& other) const& {
}
Nint::Nint(int64_t v) : mValue(v) {
- CHECK(v < 0) << "Only negative values allowed";
+ CHECK(v < 0);
}
bool Simple::operator==(const Simple& other) const& {
diff --git a/src/cppbor_parse.cpp b/src/cppbor_parse.cpp
index 6da0036..5cffe15 100644
--- a/src/cppbor_parse.cpp
+++ b/src/cppbor_parse.cpp
@@ -16,11 +16,14 @@
#include "cppbor_parse.h"
-#include <sstream>
#include <stack>
-#define LOG_TAG "CppBor"
-#include <android-base/logging.h>
+#ifndef __TRUSTY__
+ #include <android-base/logging.h>
+ #define LOG_TAG "CppBor"
+#else
+ #define CHECK(x) (void)(x)
+#endif
namespace cppbor {
@@ -28,10 +31,10 @@ namespace {
std::string insufficientLengthString(size_t bytesNeeded, size_t bytesAvail,
const std::string& type) {
- std::stringstream errStream;
- errStream << "Need " << bytesNeeded << " byte(s) for " << type << ", have " << bytesAvail
- << ".";
- return errStream.str();
+ char buf[1024];
+ snprintf(buf, sizeof(buf), "Need %zu byte(s) for %s, have %zu",
+ bytesNeeded, type.c_str(), bytesAvail);
+ return std::string(buf);
}
template <typename T, typename = std::enable_if_t<std::is_unsigned_v<T>>>