Test for NULL before calling strdup
[pspp-builds.git] / src / data / dictionary.c
index f6776780fe7362a61ec1545fa8037dada890c8e4..6e377f803212a6fbdce251ce17b36f3121e28177 100644 (file)
@@ -63,6 +63,9 @@ struct dictionary
     struct vector **vector;     /* Vectors of variables. */
     size_t vector_cnt;          /* Number of vectors. */
     struct attrset attributes;  /* Custom attributes. */
+
+    char *encoding;             /* Character encoding of string data */
+
     const struct dict_callbacks *callbacks; /* Callbacks on dictionary
                                               modification */
     void *cb_data ;                  /* Data passed to callbacks */
@@ -71,6 +74,20 @@ struct dictionary
     void *changed_data;
   };
 
+
+void
+dict_set_encoding (struct dictionary *d, const char *enc)
+{
+  d->encoding = strdup (enc);
+}
+
+const char *
+dict_get_encoding (const struct dictionary *d)
+{
+  return d->encoding ;
+}
+
+
 void
 dict_set_change_callback (struct dictionary *d,
                          void (*changed) (struct dictionary *, void*),
@@ -194,6 +211,9 @@ dict_clone (const struct dictionary *s)
   for (i = 0; i < s->vector_cnt; i++)
     d->vector[i] = vector_clone (s->vector[i], s, d);
 
+  if ( s->encoding)
+    d->encoding = strdup (s->encoding);
+
   dict_set_attributes (d, dict_get_attributes (s));
 
   return d;
@@ -1348,6 +1368,9 @@ dict_var_changed (const struct variable *v)
       const struct vardict_info *vdi = var_get_vardict (v);
       struct dictionary *d = vdi->dict;
 
+      if ( NULL == d)
+       return;
+
       if (d->changed ) d->changed (d, d->changed_data);
       if ( d->callbacks && d->callbacks->var_changed )
        d->callbacks->var_changed (d, var_get_dict_index (v), d->cb_data);