pspp-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pspp-cvs] Changes to pspp/src/dictionary.c


From: John Darrington
Subject: [Pspp-cvs] Changes to pspp/src/dictionary.c
Date: Sat, 23 Apr 2005 03:55:30 -0400

Index: pspp/src/dictionary.c
diff -u pspp/src/dictionary.c:1.16 pspp/src/dictionary.c:1.17
--- pspp/src/dictionary.c:1.16  Wed Apr 13 10:09:59 2005
+++ pspp/src/dictionary.c       Sat Apr 23 07:55:29 2005
@@ -84,6 +84,9 @@
   return hash;
 }
 
+
+
+
 static char *make_short_name(struct dictionary *dict, const char *longname) ;
 
 
@@ -96,7 +99,8 @@
   d->var = NULL;
   d->var_cnt = d->var_cap = 0;
   d->name_tab = hsh_create (8, compare_var_names, hash_var_name, NULL, NULL);
-  d->long_name_tab = hsh_create (8, compare_long_names, hash_long_name, NULL, 
NULL);
+  d->long_name_tab = hsh_create (8, compare_long_names, hash_long_name, 
+                                (hsh_free_func *) free_nte, NULL);
   d->next_value_idx = 0;
   d->split = NULL;
   d->split_cnt = 0;
@@ -232,9 +236,8 @@
   *size = bufsize;
 }
 
-
 /* Add a new entry into the dictionary's long name table, and update the 
-   corresponding varible with the relevant long name.
+   corresponding variable with the relevant long name.
 */
 void
 dict_add_longvar_entry(struct dictionary *d, 
@@ -248,7 +251,6 @@
   nte->longname = strdup(longname);
   nte->name = strdup(name);
 
-
   /* Look up the name in name_tab */
   v = hsh_find ( d->name_tab, name);
   if ( !v ) 
@@ -260,10 +262,19 @@
   v->longname = nte->longname;
 
   hsh_insert(d->long_name_tab, nte);
-  
+}
 
+/* Destroy and free up an nte */
+void
+free_nte(struct name_table_entry *nte)
+{
+  assert(nte);
+  free(nte->longname);
+  free(nte->name);
+  free(nte);
 }
 
+
 /* Destroys the aux data for every variable in D, by calling
    var_clear_aux() for each variable. */
 void
@@ -409,7 +420,11 @@
       v->name[SHORT_NAME_LEN] = '\0';
     }
   else
-    strcpy(v->name,make_short_name(d, name));
+    {
+      const char *sn = make_short_name(d, name);
+      strncpy(v->name, sn, SHORT_NAME_LEN);
+      free(sn);
+    }
   
 
   v->index = d->var_cnt;
@@ -751,12 +766,17 @@
   
   for (i = 0; i < count; i++)
     {
+      char *sn;
       struct name_table_entry key;
       struct name_table_entry *nte;
       assert (new_names[i] != NULL);
       assert (*new_names[i] != '\0');
       assert (strlen (new_names[i]) <= LONG_NAME_LEN );
-      strcpy (vars[i]->name, make_short_name(d, new_names[i]));
+      
+      sn = make_short_name(d, new_names[i]);
+      strncpy(vars[i]->name, sn, SHORT_NAME_LEN);
+      free(sn);
+      
 
 
       key.longname = vars[i]->longname;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]