Skip to content

Commit

Permalink
src: fix compiler warnings in node_buffer.cc
Browse files Browse the repository at this point in the history
Currently the following compiler warnings are generated on Linux:
../src/node_buffer.cc:
In function 'void node::Buffer::{anonymous}::StringSlice(
    const v8::FunctionCallbackInfo<v8::Value>&)
      [with node::encoding encoding = (node::encoding)1]':
../src/node_buffer.cc:54:20: warning:
'start' may be used uninitialized in this function
[-Wmaybe-uninitialized]
   if (end < start) end = start;
                    ^~~
../src/node_buffer.cc:50:10: note: 'start' was declared here
   size_t start;
          ^~~~~

This commit initializes start and end to zero to avoid these warnings.

PR-URL: #25665
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
danbev authored and addaleax committed Feb 7, 2019
1 parent f516f68 commit 2d57504
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
} while (0) \

#define SLICE_START_END(env, start_arg, end_arg, end_max) \
size_t start; \
size_t end; \
size_t start = 0; \
size_t end = 0; \
THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, start_arg, 0, &start)); \
THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, end_arg, end_max, &end)); \
if (end < start) end = start; \
Expand Down Expand Up @@ -496,9 +496,9 @@ void Copy(const FunctionCallbackInfo<Value> &args) {
SPREAD_BUFFER_ARG(buffer_obj, ts_obj);
SPREAD_BUFFER_ARG(target_obj, target);

size_t target_start;
size_t source_start;
size_t source_end;
size_t target_start = 0;
size_t source_start = 0;
size_t source_end = 0;

THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, args[2], 0, &target_start));
THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, args[3], 0, &source_start));
Expand Down Expand Up @@ -690,10 +690,10 @@ void CompareOffset(const FunctionCallbackInfo<Value> &args) {
SPREAD_BUFFER_ARG(args[0], ts_obj);
SPREAD_BUFFER_ARG(args[1], target);

size_t target_start;
size_t source_start;
size_t source_end;
size_t target_end;
size_t target_start = 0;
size_t source_start = 0;
size_t source_end = 0;
size_t target_end = 0;

THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, args[2], 0, &target_start));
THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, args[3], 0, &source_start));
Expand Down

0 comments on commit 2d57504

Please sign in to comment.