Spreadsheet implementations keep a copy of the dictionary that they build
to simplify reading cases. Until now, they shared that dictionary, in a
modifiable way, with their client. This meant, however, that if the client
modified the dictionary, it could screw up reading further cases from the
spreadsheet.
This commit fixes the problem by forcing clients to make their own copy of
the dictionary if they want to modify it.
Bug #44158.
/* PSPP - a program for statistical analysis.
/* PSPP - a program for statistical analysis.
- Copyright (C) 2007, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
+ Copyright (C) 2007, 2009, 2010, 2011, 2012, 2013, 2016 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
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
{
xmlFree (r->sheets[i].name);
}
{
xmlFree (r->sheets[i].name);
}
free (r->sheets);
state_data_destroy (&r->msd);
free (r->sheets);
state_data_destroy (&r->msd);
+ dict_destroy (r->dict);
+
free (s->file_name);
free (r);
free (s->file_name);
free (r);
- dict_destroy (spreadsheet->dict);
- spreadsheet->dict = NULL;
gnm_file_casereader_destroy (NULL, r);
gnm_file_casereader_destroy (NULL, r);
/* PSPP - a program for statistical analysis.
/* PSPP - a program for statistical analysis.
- Copyright (C) 2011, 2012, 2013 Free Software Foundation, Inc.
+ Copyright (C) 2011, 2012, 2013, 2016 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
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
{
xmlFree (r->sheets[i].name);
}
{
xmlFree (r->sheets[i].name);
}
+
+ dict_destroy (r->dict);
+
zip_reader_destroy (r->zreader);
free (r->sheets);
free (s->file_name);
zip_reader_destroy (r->zreader);
free (r->sheets);
free (s->file_name);
- dict_destroy (r->spreadsheet.dict);
- r->spreadsheet.dict = NULL;
ods_file_casereader_destroy (NULL, r);
return NULL;
ods_file_casereader_destroy (NULL, r);
return NULL;
/* PSPP - a program for statistical analysis.
/* PSPP - a program for statistical analysis.
- Copyright (C) 2007, 2010 Free Software Foundation, Inc.
+ Copyright (C) 2007, 2010, 2016 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
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
/* The total number of sheets in the "workbook" */
int n_sheets;
/* The total number of sheets in the "workbook" */
int n_sheets;
- /* The dictionary */
- struct dictionary *dict;
+ /* The dictionary for client's reference.
+ Client must clone if it needs a permanent or modifiable copy. */
+ const struct dictionary *dict;
lex_match_id (lexer, "ODS"))
{
char *filename = NULL;
lex_match_id (lexer, "ODS"))
{
char *filename = NULL;
- struct casereader *reader = NULL;
- struct dictionary *dict = NULL;
-
if (!parse_spreadsheet (lexer, &filename, &opts))
goto error;
if (!parse_spreadsheet (lexer, &filename, &opts))
goto error;
+ struct spreadsheet *spreadsheet = NULL;
if ( gnm_read_support && 0 == strncasecmp (tok, "GNM", 3))
if ( gnm_read_support && 0 == strncasecmp (tok, "GNM", 3))
- {
- struct spreadsheet *spreadsheet = gnumeric_probe (filename, true);
- if (spreadsheet == NULL)
- goto error;
- reader = gnumeric_make_reader (spreadsheet, &opts);
- dict = spreadsheet->dict;
- gnumeric_unref (spreadsheet);
- }
+ spreadsheet = gnumeric_probe (filename, true);
else if ( odf_read_support && 0 == strncasecmp (tok, "ODS", 3))
else if ( odf_read_support && 0 == strncasecmp (tok, "ODS", 3))
- {
- struct spreadsheet *spreadsheet = ods_probe (filename, true);
- if (spreadsheet == NULL)
- goto error;
- reader = ods_make_reader (spreadsheet, &opts);
- dict = spreadsheet->dict;
- ods_unref (spreadsheet);
- }
+ spreadsheet = ods_probe (filename, true);
+ if (spreadsheet == NULL)
+ goto error;
+ struct casereader *reader = spreadsheet_make_reader (spreadsheet, &opts);
- dataset_set_dict (ds, dict);
+ dataset_set_dict (ds, dict_clone (spreadsheet->dict));
dataset_set_source (ds, reader);
free (tok);
destroy_spreadsheet_read_info (&opts);
dataset_set_source (ds, reader);
free (tok);
destroy_spreadsheet_read_info (&opts);
+ spreadsheet_unref (spreadsheet);
+ spreadsheet_unref (spreadsheet);
}
else
msg (SE, _("Unsupported TYPE %s."), tok);
}
else
msg (SE, _("Unsupported TYPE %s."), tok);
case SPREADSHEET_GNUMERIC:
{
reader = spreadsheet_make_reader (ia->spreadsheet, &sro);
case SPREADSHEET_GNUMERIC:
{
reader = spreadsheet_make_reader (ia->spreadsheet, &sro);
- ia->dict = ia->spreadsheet->dict;
+ ia->dict = dict_clone (ia->spreadsheet->dict);