From 41cdbd750801f8c84ce1b6fb72302d0597863105 Mon Sep 17 00:00:00 2001 From: tpoisseau <22891227+tpoisseau@users.noreply.github.com> Date: Wed, 28 Aug 2024 09:17:03 +0200 Subject: [PATCH] chore: ensure keys and values have same size Refs: https://github.com/nodejs/node/pull/54213#discussion_r1733149688 --- src/node_sqlite.cc | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/node_sqlite.cc b/src/node_sqlite.cc index be99229930058c..144de8d238603e 100644 --- a/src/node_sqlite.cc +++ b/src/node_sqlite.cc @@ -528,8 +528,9 @@ void StatementSync::IterateReturnCallback( LocalVector values(isolate, {Boolean::New(isolate, true), Null(isolate)}); - Local result = - Object::New(isolate, Null(isolate), keys.data(), values.data(), 2); + DCHECK_EQ(keys.size(), values.size()); + Local result = Object::New( + isolate, Null(isolate), keys.data(), values.data(), keys.size()); args.GetReturnValue().Set(result); } @@ -554,8 +555,9 @@ void StatementSync::IterateNextCallback( LocalVector values(isolate, {Boolean::New(isolate, true), Null(isolate)}); - Local result = - Object::New(isolate, Null(isolate), keys.data(), values.data(), 2); + DCHECK_EQ(keys.size(), values.size()); + Local result = Object::New( + isolate, Null(isolate), keys.data(), values.data(), keys.size()); args.GetReturnValue().Set(result); return; } @@ -579,8 +581,9 @@ void StatementSync::IterateNextCallback( LocalVector keys(isolate, {env->done_string(), env->value_string()}); LocalVector values(isolate, {Boolean::New(isolate, false), row}); - Local result = - Object::New(isolate, Null(isolate), keys.data(), values.data(), 2); + DCHECK_EQ(keys.size(), values.size()); + Local result = Object::New( + isolate, Null(isolate), keys.data(), values.data(), keys.size()); args.GetReturnValue().Set(result); } @@ -629,8 +632,9 @@ void StatementSync::Iterate(const FunctionCallbackInfo& args) { .ToLocalChecked() .As(); + DCHECK_EQ(keys.size(), values.size()); Local iterable_iterator = Object::New( - isolate, js_iterator_prototype, keys.data(), values.data(), 2); + isolate, js_iterator_prototype, keys.data(), values.data(), keys.size()); args.GetReturnValue().Set(iterable_iterator); }