From 21fb18e7f56a10004d2245f4e529d905a72f29f0 Mon Sep 17 00:00:00 2001 From: Giloo <33936193+GillesDuvert@users.noreply.github.com> Date: Mon, 6 May 2024 21:46:45 +0200 Subject: [PATCH] Close 1814 (#1827) --- src/hash.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/hash.cpp b/src/hash.cpp index b1520baa4..4bcae1441 100644 --- a/src/hash.cpp +++ b/src/hash.cpp @@ -2961,8 +2961,11 @@ static BaseGDL* hash_create( EnvT* e, bool isordered=false) nEntries = key->N_Elements(); if(trace_me) std::cout << " nEntries= " << nEntries; } - } // nParam==1 - + } else if( nParam == 2) { //ckeck key/value similar number of elements + if ((e->GetPar(0))->N_Elements() != (e->GetPar(1))->N_Elements()) e->Throw("Key and Value must have the same number of elements."); + } else { + if (nParam % 2 != 0) e->Throw("Incorrect number of arguments."); + } // Count the possible entries, no check for total correctness. for( SizeT eIx=0; eIx < nParam/2; ++eIx) { BaseGDL* key = e->GetPar( 2 * eIx); @@ -2992,10 +2995,10 @@ static BaseGDL* hash_create( EnvT* e, bool isordered=false) DStructGDL* hashStruct = GetOBJ( newObj, 0); if( nParam == 1) { if( key->N_Elements() == 1) { - InsertIntoHashTable( hashStruct, hashTable, key, NULL); + InsertIntoHashTable( hashStruct, hashTable, key, NullGDL::GetSingleInstance()); } else { for( SizeT kIx=0; kIx < nEntries; ++kIx) - InsertIntoHashTable( hashStruct, hashTable, key->NewIx(kIx), NULL); + InsertIntoHashTable( hashStruct, hashTable, key->NewIx(kIx), NullGDL::GetSingleInstance()); } newObjGuard.Release(); return newObj;