src: enforce assumptions in FIXED_ONE_BYTE_STRING · nodejs/node@dfd4962

Original file line numberDiff line numberDiff line change

@@ -346,17 +346,19 @@ inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,

346346

std::string_view str);

347347
348348

// Used to be a macro, hence the uppercase name.

349-

template <int N>

350-

inline v8::Local<v8::String> FIXED_ONE_BYTE_STRING(

351-

v8::Isolate* isolate,

352-

const char(&data)[N]) {

349+

template <std::size_t N>

350+

requires(N > 0)

351+

inline v8::Local<v8::String> FIXED_ONE_BYTE_STRING(v8::Isolate* isolate,

352+

const char (&data)[N]) {

353+

CHECK_EQ(data[N - 1], '\0');

353354

return OneByteString(isolate, data, N - 1);

354355

}

355356
356357

template <std::size_t N>

358+

requires(N > 0)

357359

inline v8::Local<v8::String> FIXED_ONE_BYTE_STRING(

358-

v8::Isolate* isolate,

359-

const std::array<char, N>& arr) {

360+

v8::Isolate* isolate, const std::array<char, N>& arr) {

361+

CHECK_EQ(arr[N - 1], '\0');

360362

return OneByteString(isolate, arr.data(), N - 1);

361363

}

362364