summaryrefslogtreecommitdiff
path: root/libs/binder/Utils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libs/binder/Utils.cpp')
-rw-r--r--libs/binder/Utils.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/libs/binder/Utils.cpp b/libs/binder/Utils.cpp
index 0314b0fea7..47fd17dcb1 100644
--- a/libs/binder/Utils.cpp
+++ b/libs/binder/Utils.cpp
@@ -16,6 +16,7 @@
#include "Utils.h"
+#include <android-base/logging.h>
#include <string.h>
namespace android {
@@ -24,4 +25,22 @@ void zeroMemory(uint8_t* data, size_t size) {
memset(data, 0, size);
}
+std::string HexString(const void* bytes, size_t len) {
+ CHECK(bytes != nullptr || len == 0) << bytes << " " << len;
+
+ // b/132916539: Doing this the 'C way', std::setfill triggers ubsan implicit conversion
+ const uint8_t* bytes8 = static_cast<const uint8_t*>(bytes);
+ const char chars[] = "0123456789abcdef";
+ std::string result;
+ result.resize(len * 2);
+
+ for (size_t i = 0; i < len; i++) {
+ const auto c = bytes8[i];
+ result[2 * i] = chars[c >> 4];
+ result[2 * i + 1] = chars[c & 0xf];
+ }
+
+ return result;
+}
+
} // namespace android