src,buffer: evaluate THROW_AND_RETURN_IF_OOB() expression only once

There's no need to evaluate the expression passed into the macro more
than once.

Fixes: https://github.com/nodejs/node/issues/41935
Signed-off-by: Darshan Sen <raisinten@gmail.com>

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Darshan Sen authored and GitHub committed 2022-02-18 00:05:42 +01:00
1 parent 6db686710e
commit 5edad38328
1 file changed
+3 -2
+3 -2
View File
@@ -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) \