Skip to content

Commit

Permalink
src,buffer: evaluate THROW_AND_RETURN_IF_OOB() expression only once
Browse files Browse the repository at this point in the history
There's no need to evaluate the expression passed into the macro more
than once.

Fixes: #41935
Signed-off-by: Darshan Sen <raisinten@gmail.com>

PR-URL: #41945
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
RaisinTen authored and bengl committed Feb 22, 2022
1 parent 782506c commit 43c12f4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@

#define THROW_AND_RETURN_IF_OOB(r) \
do { \
if ((r).IsNothing()) return; \
if (!(r).FromJust()) \
Maybe<bool> m = (r); \
if (m.IsNothing()) return; \
if (!m.FromJust()) \
return node::THROW_ERR_OUT_OF_RANGE(env, "Index out of range"); \
} while (0) \

Expand Down

0 comments on commit 43c12f4

Please sign in to comment.