names array is not NULL-terminated; use 'oarg' which should be count of names at this point

This commit is contained in:
K. Lange 2023-12-30 11:45:23 +09:00
parent c7caf52f3e
commit 0c52d44d3e

View File

@ -429,10 +429,10 @@ int krk_parseVArgs(
KrkTableEntry * entry = &AS_DICT(argv[argc])->entries[i];
if (IS_STRING(entry->key)) {
/* See if this was the name of an argument, which means it was already provided as a positional argument. */
for (const char ** name = names; *name; ++name) {
if (**name && !strcmp(*name, AS_CSTRING(entry->key))) {
for (int j = 0; j < oarg; ++j) {
if (*names[j] && strlen(names[j]) == AS_STRING(entry->key)->length && !strcmp(names[j], AS_CSTRING(entry->key))) {
krk_runtimeError(vm.exceptions->typeError, "%s() got multiple values for argument '%s'",
_method_name, *name);
_method_name, names[j]);
return 0;
}
}