diff options
author | Bram Bonné <brambonne@google.com> | 2020-10-26 15:10:01 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-10-26 15:10:01 +0000 |
commit | 35847175d0cc87a21f79e6babbd4ad327bc1fa4c (patch) | |
tree | 78b1e8469b084dc55846ba8f23260bb04b5c0428 | |
parent | 0d8dd3aa63c6d507b76332bb6374edc2ed2a4348 (diff) | |
parent | 9eba3ebf12941cf3bf52aa282cd6d65a34247e3f (diff) | |
download | libcppbor-35847175d0cc87a21f79e6babbd4ad327bc1fa4c.tar.gz |
Merge "Add Trusty support to libcppbor." am: 843849541c am: 6e3a18c571 am: b2fe32dba9 am: 9eba3ebf12
Original change: https://android-review.googlesource.com/c/platform/external/libcppbor/+/1466585
Change-Id: If3b1fc8dcb984c89a7263b976c751b8b41cbb57b
-rw-r--r-- | rules.mk | 29 | ||||
-rw-r--r-- | src/cppbor.cpp | 10 | ||||
-rw-r--r-- | src/cppbor_parse.cpp | 17 |
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>>> |