From b357ed1cd249645d0d70b9713e15238a6fc0ae78 Mon Sep 17 00:00:00 2001 From: Darshan Sen Date: Sat, 12 Feb 2022 20:22:17 +0530 Subject: [PATCH] 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 --- src/node_buffer.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 48df1323ca7215..be9324a8bd82ab 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -41,8 +41,9 @@ #define THROW_AND_RETURN_IF_OOB(r) \ do { \ - if ((r).IsNothing()) return; \ - if (!(r).FromJust()) \ + Maybe m = (r); \ + if (m.IsNothing()) return; \ + if (!m.FromJust()) \ return node::THROW_ERR_OUT_OF_RANGE(env, "Index out of range"); \ } while (0) \