v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
hex-format.cc
Go to the documentation of this file.
1// Copyright 2022 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
7#include <stddef.h>
8#include <stdint.h>
9
10#include "src/base/logging.h"
11
12namespace v8 {
13namespace internal {
14
15void FormatBytesToHex(char* formatted, size_t size_of_formatted,
16 const uint8_t* val, size_t size_of_val) {
17 // Prevent overflow by ensuring that the value can't exceed
18 // 0x20000000 in length, which would be 0x40000000 when formatted
19 CHECK_LT(size_of_val, 0x20000000);
20 CHECK(size_of_formatted >= (size_of_val * 2));
21
22 for (size_t index = 0; index < size_of_val; index++) {
23 size_t dest_index = index << 1;
24 snprintf(&formatted[dest_index], size_of_formatted - dest_index, "%02x",
25 val[index]);
26 }
27}
28
29} // namespace internal
30} // namespace v8
icu::number::FormattedNumber formatted
void FormatBytesToHex(char *formatted, size_t size_of_formatted, const uint8_t *val, size_t size_of_val)
Definition hex-format.cc:15
#define CHECK(condition)
Definition logging.h:124
#define CHECK_LT(lhs, rhs)