Add "x" prefix to calls to plain malloc(), calloc(), strdup(), realloc().
[pspp-builds.git] / src / data / gnumeric-reader.c
index 5a0c75ede293a21052228a87b295a070398f3e1f..2e92e3f5127595b0fd2d75ba0bb96e8af94fd993 100644 (file)
@@ -314,11 +314,10 @@ static void
 convert_xml_string_to_value (struct ccase *c, const struct variable *var,
                             const xmlChar *xv)
 {
-  char *text;
   int n_bytes = 0;
   union value *v = case_data_rw (c, var);
 
-  text = recode_string (CONV_UTF8_TO_PSPP, (const char *) xv, -1);
+  const char *text = (const char *) xv;
 
   if ( text)
     n_bytes = MIN (var_get_width (var), strlen (text));
@@ -335,8 +334,6 @@ convert_xml_string_to_value (struct ccase *c, const struct variable *var,
       if ( errno != 0 || endptr == text)
        v->f = SYSMIS;
     }
-
-  free (text);
 }
 
 struct var_spec
@@ -451,7 +448,7 @@ gnumeric_open_reader (struct gnumeric_read_info *gri, struct dictionary **dict)
       if ( idx  >= n_var_specs )
        {
          n_var_specs =  idx + 1 ;
-         var_spec = realloc (var_spec, sizeof (*var_spec) * n_var_specs);
+         var_spec = xrealloc (var_spec, sizeof (*var_spec) * n_var_specs);
          var_spec [idx].name = NULL;
          var_spec [idx].width = -1;
          var_spec [idx].first_value = NULL;
@@ -459,16 +456,14 @@ gnumeric_open_reader (struct gnumeric_read_info *gri, struct dictionary **dict)
 
       if ( r->node_type == XML_READER_TYPE_TEXT )
        {
-         char *text ;
          xmlChar *value = xmlTextReaderValue (r->xtr);
-
-         text = recode_string (CONV_UTF8_TO_PSPP, (const char *) value, -1);
+         const char *text  = (const char *) value;
 
          if ( r->row < r->start_row)
            {
              if ( gri->read_names )
                {
-                 var_spec [idx].name = strdup (text);
+                 var_spec [idx].name = xstrdup (text);
                }
            }
          else
@@ -481,7 +476,6 @@ gnumeric_open_reader (struct gnumeric_read_info *gri, struct dictionary **dict)
            }
 
          free (value);
-         free (text);
        }
       else if ( r->node_type == XML_READER_TYPE_ELEMENT
                && r->state == STATE_CELL)
@@ -503,6 +497,8 @@ gnumeric_open_reader (struct gnumeric_read_info *gri, struct dictionary **dict)
   /* Create the dictionary and populate it */
   *dict = r->dict = dict_create ();
 
+  dict_set_encoding (r->dict, (const char *) xmlTextReaderConstEncoding (r->xtr));
+  
   r->value_cnt = 0;
 
   for (i = 0 ; i < n_var_specs ; ++i )