Before recoding a variable's name, check that it
authorJohn Darrington <john@darrington.wattle.id.au>
Sat, 18 Jul 2009 09:32:46 +0000 (11:32 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 18 Jul 2009 09:32:46 +0000 (11:32 +0200)
doesn't clash with an existing one.

Thanks to Ben Pfaff for pointing out this potential
problem.

src/data/sys-file-reader.c

index 5850887fb4aaa9d3679603f2a198ad5cffdbac11..0f583a12a5005fe360abd8662847039742b9afbb 100644 (file)
@@ -202,8 +202,17 @@ recode_strings (struct dictionary *dict)
     {
       /* Convert the long variable name */
       struct variable *var = dict_get_var (dict, i);
-      char *utf8_name = recode_string (UTF8, enc, var_get_name (var), -1);
-      dict_rename_var (dict, var, utf8_name);
+      const char *native_name = var_get_name (var);
+      char *utf8_name = recode_string (UTF8, enc, native_name, -1);
+      if ( 0 != strcmp (utf8_name, native_name))
+       {
+         if ( NULL == dict_lookup_var (dict, utf8_name))
+           dict_rename_var (dict, var, utf8_name);
+         else
+           msg (MW,
+            _("Recoded variable name duplicates an existing `%s' within system file."), utf8_name);
+    }
+
       free (utf8_name);
 
       /* Convert the variable label */