Fix a crash when attempting to add vectors whose names differed only in case.
authorJohn Darrington <john@cellform.com>
Sun, 2 Jun 2024 15:11:36 +0000 (17:11 +0200)
committerJohn Darrington <john@cellform.com>
Sun, 2 Jun 2024 15:11:36 +0000 (17:11 +0200)
Partial fix for bug #65545

src/language/commands/vector.c
tests/language/commands/vector.at

index 0a543136b5a4969c4e095afaa00c5499e5e16824..42c42e5edaee161c6958ba0caec85b642601d8a2 100644 (file)
@@ -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);
index 426ab5a0f261c9538dc5c468ced59e1f126e88c0..8eb5a5390ded6c794ada6641227b4ddaf346b1f6 100644 (file)
@@ -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