X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fods-reader.c;h=170c005739b9eed6070465743d20ac4de521bab9;hb=811c669032a18cfff53291a98e5803afdf39db36;hp=51ee5ac39ace8994901deed27ef1e236ef56591d;hpb=2f7b367bf796c63c595ac837b716cce535ffd5bf;p=pspp diff --git a/src/data/ods-reader.c b/src/data/ods-reader.c index 51ee5ac39a..170c005739 100644 --- a/src/data/ods-reader.c +++ b/src/data/ods-reader.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2011 Free Software Foundation, Inc. + Copyright (C) 2011, 2012 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -127,7 +127,7 @@ ods_file_casereader_destroy (struct casereader *reader UNUSED, void *r_) xmlFreeTextReader (r->xtr); if ( ! ds_is_empty (&r->ods_errs)) - msg (ME, ds_cstr (&r->ods_errs)); + msg (ME, "%s", ds_cstr (&r->ods_errs)); ds_destroy (&r->ods_errs); @@ -315,19 +315,20 @@ convert_xml_to_value (struct ccase *c, const struct variable *var, value_copy_str_rpad (v, var_get_width (var), xmv->text, ' '); else { + const char *text ; const struct fmt_spec *fmt = var_get_write_format (var); enum fmt_category fc = fmt_get_category (fmt->type); assert ( fc != FMT_CAT_STRING); - const char *text = xmv->value ? CHAR_CAST (const char *, xmv->value): - CHAR_CAST (const char *, xmv->text); + text = + xmv->value ? CHAR_CAST (const char *, xmv->value) : CHAR_CAST (const char *, xmv->text); - data_in (ss_cstr (text), "UTF-8", - fmt->type, - v, - var_get_width (var), - "UTF-8"); + free (data_in (ss_cstr (text), "UTF-8", + fmt->type, + v, + var_get_width (var), + "UTF-8")); } } @@ -344,12 +345,14 @@ ods_open_reader (struct spreadsheet_read_info *gri, struct dictionary **dict) int n_var_specs = 0; struct ods_reader *r = xzalloc (sizeof *r); + struct zip_member *content = NULL; + struct zip_reader *zreader ; + xmlChar *val_string = NULL; r->read_names = gri->read_names; ds_init_empty (&r->ods_errs); - struct zip_reader *zreader = zip_reader_create (gri->file_name, &r->ods_errs); - struct zip_member *content = NULL; + zreader = zip_reader_create (gri->file_name, &r->ods_errs); if ( NULL == zreader) { @@ -408,8 +411,10 @@ ods_open_reader (struct spreadsheet_read_info *gri, struct dictionary **dict) /* If CELLRANGE was given, then we know how many variables should be read */ if ( r->stop_col != -1 ) { + assert (var_spec == NULL); n_var_specs = r->stop_col - r->start_col + 1; var_spec = xrealloc (var_spec, sizeof (*var_spec) * n_var_specs); + memset (var_spec, '\0', sizeof (*var_spec) * n_var_specs); } @@ -457,7 +462,7 @@ ods_open_reader (struct spreadsheet_read_info *gri, struct dictionary **dict) var_spec = xrealloc (var_spec, sizeof (*var_spec) * (idx + 1)); /* xrealloc (unlike realloc) doesn't initialise its memory to 0 */ - memset (var_spec + n_var_specs * sizeof (*var_spec), + memset (var_spec + n_var_specs, 0, (n_var_specs - idx + 1) * sizeof (*var_spec)); n_var_specs = idx + 1; @@ -473,7 +478,6 @@ ods_open_reader (struct spreadsheet_read_info *gri, struct dictionary **dict) } } - xmlChar *val_string = NULL; /* Read in the first row of data */ while (1 == xmlTextReaderRead (r->xtr)) { @@ -588,6 +592,10 @@ ods_open_reader (struct spreadsheet_read_info *gri, struct dictionary **dict) free (var_spec); + dict_destroy (r->dict); + ods_file_casereader_destroy (NULL, r); + + return NULL; }