Skip to content

Commit 176b82d

Browse files
committed
src: example use of gsl::narrow to uncover a bug
1 parent 564123b commit 176b82d

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

deps/GSL/gsl/gsl_assert

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,15 @@ namespace details
125125
#if defined(GSL_TERMINATE_ON_CONTRACT_VIOLATION)
126126

127127
template <typename Exception>
128-
[[noreturn]] void throw_exception(Exception&&) noexcept
128+
[[noreturn]] void throw_exception(Exception&& ex) noexcept
129129
{
130-
gsl::details::terminate();
130+
static const char* const args[] = {
131+
__FILE__,
132+
STRINGIFY(__LINE__),
133+
ex.what(),
134+
PRETTY_FUNCTION_NAME
135+
};
136+
node::Assert(&args);
131137
}
132138

133139
#else

node.gypi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
'deps/v8/include',
3030
'src',
3131
],
32+
'defines': [ 'GSL_TERMINATE_ON_CONTRACT_VIOLATION', ],
3233
# Putting these explicitly here so not to be dependant on common.gypi.
3334
'cflags': [ '-Wall', '-Wextra', '-Wno-unused-parameter', ],
3435
'xcode_settings': {

src/node_internals.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
#include <string>
4242
#include <vector>
4343

44+
#include <gsl/gsl_util>
45+
4446
// Custom constants used by both node_constants.cc and node_zlib.cc
4547
#define Z_MIN_WINDOWBITS 8
4648
#define Z_MAX_WINDOWBITS 15
@@ -323,7 +325,7 @@ v8::Local<v8::Value> FillStatsArray(AliasedBuffer<NativeT, V8T>* fields_ptr,
323325
#else
324326
fields[offset + 6] = 0;
325327
#endif
326-
fields[offset + 7] = s->st_ino;
328+
fields[offset + 7] = gsl::narrow<NativeT>(s->st_ino);
327329
fields[offset + 8] = s->st_size;
328330
#if defined(__POSIX__)
329331
fields[offset + 9] = s->st_blocks;

0 commit comments

Comments
 (0)