From: John Darrington Date: Sun, 2 Jun 2024 15:11:36 +0000 (+0200) Subject: Fix a crash when attempting to add vectors whose names differed only in case. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=950fddc76ddf15c99e8a82cd4b43a04dfd6993df;p=pspp Fix a crash when attempting to add vectors whose names differed only in case. Partial fix for bug #65545 --- diff --git a/src/language/commands/vector.c b/src/language/commands/vector.c index 0a543136b5..42c42e5eda 100644 --- a/src/language/commands/vector.c +++ b/src/language/commands/vector.c @@ -32,7 +32,7 @@ #include "libpspp/misc.h" #include "libpspp/pool.h" #include "libpspp/str.h" -#include "libpspp/string-set.h" +#include "libpspp/stringi-set.h" #include "gl/intprops.h" #include "gl/xalloc.h" @@ -172,7 +172,7 @@ cmd_vector (struct lexer *lexer, struct dataset *ds) /* Check that none of the variables exist and that their names are not excessively long. */ - struct string_set new_names = STRING_SET_INITIALIZER (new_names); + struct stringi_set new_names = STRINGI_SET_INITIALIZER (new_names); for (size_t i = 0; i < n_vectors; i++) for (size_t j = 0; j < n_vars; j++) { @@ -192,21 +192,22 @@ cmd_vector (struct lexer *lexer, struct dataset *ds) _("%s is an existing variable name."), name); free (name); - string_set_destroy (&new_names); + stringi_set_destroy (&new_names); goto error; } - if (!string_set_insert_nocopy (&new_names, name)) + + if (!stringi_set_insert_nocopy (&new_names, name)) { /* name was already freed. */ lex_ofs_error ( lexer, vectors_start, end_ofs, _("Two different vectors add variable %s%zu."), vectors[i], j + 1); - string_set_destroy (&new_names); + stringi_set_destroy (&new_names); goto error; } } - string_set_destroy (&new_names); + stringi_set_destroy (&new_names); /* Finally create the variables and vectors. */ struct variable **vars = pool_nmalloc (pool, n_vars, sizeof *vars); diff --git a/tests/language/commands/vector.at b/tests/language/commands/vector.at index 426ab5a0f2..8eb5a5390d 100644 --- a/tests/language/commands/vector.at +++ b/tests/language/commands/vector.at @@ -180,4 +180,21 @@ AT_CHECK([pspp --testing-mode -O format=csv insert.sps], [1], [dnl 16 | VECTOR v v1 (123). | ^~~~~~~~~~" ]) -AT_CLEANUP \ No newline at end of file +AT_CLEANUP + + +AT_SETUP([VECTOR - names differing only in case]) + +AT_DATA([vector.sps], [dnl +data list /fxx 1-11 +vec E2 e(22) +display vectors. +]) + +AT_CHECK([pspp -o pspp.csv vector.sps], [1], [dnl +vector.sps:2.5-2.12: error: VECTOR: Two different vectors add variable e21. + 2 | vec E2 e(22) + | ^~~~~~~~ +vector.sps:3: note: DISPLAY: No vectors defined. +]) +AT_CLEANUP