In review commit
503f53bfdde "Read dictionary encoding from data files"
I noticed uses of plain strdup() (not xstrdup()). Some greps showed that
there were several other uses of strdup(), as well as calloc(), malloc(),
and realloc(), in the source tree. This commit adds "x" prefixes to each
of them, to ensure proper error handling.
17 files changed:
/* PSPP - a program for statistical analysis.
/* PSPP - a program for statistical analysis.
- Copyright (C) 1997-9, 2000, 2006, 2007 Free Software Foundation, Inc.
+ Copyright (C) 1997-9, 2000, 2006, 2007, 2009 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
dict_set_encoding (struct dictionary *d, const char *enc)
{
if (enc)
dict_set_encoding (struct dictionary *d, const char *enc)
{
if (enc)
- d->encoding = strdup (enc);
+ d->encoding = xstrdup (enc);
d->vector[i] = vector_clone (s->vector[i], s, d);
if ( s->encoding)
d->vector[i] = vector_clone (s->vector[i], s, d);
if ( s->encoding)
- d->encoding = strdup (s->encoding);
+ d->encoding = xstrdup (s->encoding);
dict_set_attributes (d, dict_get_attributes (s));
dict_set_attributes (d, dict_get_attributes (s));
if ( idx >= n_var_specs )
{
n_var_specs = idx + 1 ;
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;
var_spec [idx].name = NULL;
var_spec [idx].width = -1;
var_spec [idx].first_value = NULL;
{
if ( gri->read_names )
{
{
if ( gri->read_names )
{
- var_spec [idx].name = strdup (text);
+ var_spec [idx].name = xstrdup (text);
/* New in SPSS 16. Contains a single string that describes
the character encoding, e.g. "windows-1252". */
{
/* New in SPSS 16. Contains a single string that describes
the character encoding, e.g. "windows-1252". */
{
- char *encoding = calloc (size, count + 1);
+ char *encoding = xcalloc (size, count + 1);
read_string (r, encoding, count + 1);
dict_set_encoding (dict, encoding);
return;
read_string (r, encoding, count + 1);
dict_set_encoding (dict, encoding);
return;
/* PSPP - a program for statistical analysis.
/* PSPP - a program for statistical analysis.
- Copyright (C) 2007, 2008 Free Software Foundation, Inc.
+ Copyright (C) 2007, 2008, 2009 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
#include <language/lexer/lexer.h>
#include <libpspp/message.h>
#include <language/lexer/lexer.h>
#include <libpspp/message.h>
#include "gettext.h"
#define _(msgid) gettext (msgid)
#define N_(msgid) (msgid)
#include "gettext.h"
#define _(msgid) gettext (msgid)
#define N_(msgid) (msgid)
if (!lex_force_string (lexer))
goto error;
if (!lex_force_string (lexer))
goto error;
- psql.conninfo = strdup (ds_cstr (lex_tokstr (lexer)));
+ psql.conninfo = xstrdup (ds_cstr (lex_tokstr (lexer)));
if (!lex_force_string (lexer))
goto error;
if (!lex_force_string (lexer))
goto error;
- gri.file_name = strdup (ds_cstr (lex_tokstr (lexer)));
+ gri.file_name = xstrdup (ds_cstr (lex_tokstr (lexer)));
if ( ! lex_force_string (lexer) )
goto error;
if ( ! lex_force_string (lexer) )
goto error;
- gri.sheet_name = strdup (ds_cstr (lex_tokstr (lexer)));
+ gri.sheet_name = xstrdup (ds_cstr (lex_tokstr (lexer)));
gri.sheet_index = -1;
}
else if (lex_match_id (lexer, "INDEX"))
gri.sheet_index = -1;
}
else if (lex_match_id (lexer, "INDEX"))
if ( ! lex_force_string (lexer) )
goto error;
if ( ! lex_force_string (lexer) )
goto error;
- gri.cell_range = strdup (ds_cstr (lex_tokstr (lexer)));
+ gri.cell_range = xstrdup (ds_cstr (lex_tokstr (lexer)));
const char *s;
s = var_lookup_value_label (indep_var, &gp.v.g_value[0]);
const char *s;
s = var_lookup_value_label (indep_var, &gp.v.g_value[0]);
- val_lab[0] = s ? strdup (s) : NULL;
+ val_lab[0] = s ? xstrdup (s) : NULL;
s = var_lookup_value_label (indep_var, &gp.v.g_value[1]);
s = var_lookup_value_label (indep_var, &gp.v.g_value[1]);
- val_lab[1] = s ? strdup (s) : NULL;
+ val_lab[1] = s ? xstrdup (s) : NULL;
- val_lab[0] = calloc (sizeof (char), MAX_SHORT_STRING + 1);
- val_lab[1] = calloc (sizeof (char), MAX_SHORT_STRING + 1);
+ val_lab[0] = xcalloc (sizeof (char), MAX_SHORT_STRING + 1);
+ val_lab[1] = xcalloc (sizeof (char), MAX_SHORT_STRING + 1);
memcpy (val_lab[0], gp.v.g_value[0].s, MAX_SHORT_STRING);
memcpy (val_lab[1], gp.v.g_value[1].s, MAX_SHORT_STRING);
}
memcpy (val_lab[0], gp.v.g_value[0].s, MAX_SHORT_STRING);
memcpy (val_lab[1], gp.v.g_value[1].s, MAX_SHORT_STRING);
}
/* PSPP - a program for statistical analysis.
/* PSPP - a program for statistical analysis.
- Copyright (C) 2008 Free Software Foundation, Inc.
+ Copyright (C) 2008, 2009 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
#include <assert.h>
#include <stdlib.h>
#include <assert.h>
#include <stdlib.h>
static size_t capacity_to_mask (size_t capacity);
/* Initializes MAP as a new hash map that is initially empty. */
static size_t capacity_to_mask (size_t capacity);
/* Initializes MAP as a new hash map that is initially empty. */
assert ((new_mask & (new_mask + 1)) == 0);
if (new_mask)
assert ((new_mask & (new_mask + 1)) == 0);
if (new_mask)
- new_buckets = calloc (new_mask + 1, sizeof *new_buckets);
+ new_buckets = xcalloc (new_mask + 1, sizeof *new_buckets);
else
{
new_buckets = &map->one;
else
{
new_buckets = &map->one;
#endif /* ENABLE_NLS */
assert (default_encoding == NULL);
#endif /* ENABLE_NLS */
assert (default_encoding == NULL);
- default_encoding = strdup (locale_charset ());
+ default_encoding = xstrdup (locale_charset ());
set_default_encoding (const char *enc)
{
free (default_encoding);
set_default_encoding (const char *enc)
{
free (default_encoding);
- default_encoding = strdup (enc);
+ default_encoding = xstrdup (enc);
bool ok = true;
char *c_encoding;
char *loc_encoding;
bool ok = true;
char *c_encoding;
char *loc_encoding;
- char *tmp = strdup (setlocale (LC_CTYPE, NULL));
+ char *tmp = xstrdup (setlocale (LC_CTYPE, NULL));
setlocale (LC_CTYPE, "C");
setlocale (LC_CTYPE, "C");
- c_encoding = strdup (locale_charset ());
+ c_encoding = xstrdup (locale_charset ());
setlocale (LC_CTYPE, loc);
setlocale (LC_CTYPE, loc);
- loc_encoding = strdup (locale_charset ());
+ loc_encoding = xstrdup (locale_charset ());
if ( 0 == strcmp (loc_encoding, c_encoding))
if ( 0 == strcmp (loc_encoding, c_encoding))
- char *ol = strdup (setlocale (LC_NUMERIC, NULL));
+ char *ol = xstrdup (setlocale (LC_NUMERIC, NULL));
setlocale (LC_NUMERIC, "");
#if HAVE_NL_LANGINFO
setlocale (LC_NUMERIC, "");
#if HAVE_NL_LANGINFO
/* PSPP - a program for statistical analysis.
/* PSPP - a program for statistical analysis.
- Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
+ Copyright (C) 1997-9, 2000, 2006, 2009 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
struct msg *new_msg = xmalloc (sizeof *m);
*new_msg = *m;
struct msg *new_msg = xmalloc (sizeof *m);
*new_msg = *m;
- new_msg->text = strdup(m->text);
+ new_msg->text = xstrdup(m->text);
/* PSPPIRE - a graphical user interface for PSPP.
/* PSPPIRE - a graphical user interface for PSPP.
- Copyright (C) 2007 Free Software Foundation
+ Copyright (C) 2007, 2009 Free Software Foundation
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
output_name = g_convert (fname, -1, target_encoding,
"UTF-8", NULL, NULL, err);
#else
output_name = g_convert (fname, -1, target_encoding,
"UTF-8", NULL, NULL, err);
#else
- output_name = strdup (fname);
+ output_name = xstrdup (fname);
#endif
return output_name;
#endif
return output_name;
#include "syntax-editor-source.h"
#include <language/lexer/lexer.h>
#include "syntax-editor-source.h"
#include <language/lexer/lexer.h>
#include <gettext.h>
#define _(msgid) gettext (msgid)
#define N_(msgid) msgid
#include <gettext.h>
#define _(msgid) gettext (msgid)
#define N_(msgid) msgid
return g_strdup_printf ("%s.sps", filename);
}
return g_strdup_printf ("%s.sps", filename);
}
- return strdup (filename);
+ return xstrdup (filename);
name = g_value_get_string (&def);
}
name = g_value_get_string (&def);
}
- candidate_name = strdup (name);
+ candidate_name = xstrdup (name);
while ( psppire_window_register_lookup (reg, candidate_name))
{
while ( psppire_window_register_lookup (reg, candidate_name))
{
{
window->name = NULL;
window->menu = NULL;
{
window->name = NULL;
window->menu = NULL;
- window->description = strdup ("");
+ window->description = xstrdup ("");
window->menuitem_table = g_hash_table_new (g_str_hash, g_str_equal);
window->menuitem_table = g_hash_table_new (g_str_hash, g_str_equal);
g_free (utf8);
if ( filename == NULL)
g_free (utf8);
if ( filename == NULL)
- filename = strdup (arg);
+ filename = xstrdup (arg);
psppire_window_load (PSPPIRE_WINDOW (the_data_window), filename);
psppire_window_load (PSPPIRE_WINDOW (the_data_window), filename);
/* PSPPIRE - a graphical user interface for PSPP.
/* PSPPIRE - a graphical user interface for PSPP.
- Copyright (C) 2007 Free Software Foundation
+ Copyright (C) 2007, 2009 Free Software Foundation
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
struct new_value *copy = g_memdup (nv, sizeof (*copy));
if ( nv->type == NV_STRING )
struct new_value *copy = g_memdup (nv, sizeof (*copy));
if ( nv->type == NV_STRING )
- copy->v.s = strdup (nv->v.s);
+ copy->v.s = xstrdup (nv->v.s);
/* PSPPIRE - a graphical user interface for PSPP.
/* PSPPIRE - a graphical user interface for PSPP.
- Copyright (C) 2007, 2008 Free Software Foundation, Inc.
+ Copyright (C) 2007, 2008, 2009 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
(GTK_TOGGLE_BUTTON (get_widget_assert (scd->xml,
"radiobutton-all"))))
{
(GTK_TOGGLE_BUTTON (get_widget_assert (scd->xml,
"radiobutton-all"))))
{
}
string = g_string_new ("");
}
string = g_string_new ("");
/* PSPPIRE - a graphical user interface for PSPP.
/* PSPPIRE - a graphical user interface for PSPP.
- Copyright (C) 2007 Free Software Foundation
+ Copyright (C) 2007, 2009 Free Software Foundation
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
gtk_window_set_transient_for (GTK_WINDOW (grps->dialog), parent);
gtk_window_set_transient_for (GTK_WINDOW (grps->dialog), parent);
- grps->val[0] = strdup ("");
- grps->val[1] = strdup ("");
+ grps->val[0] = xstrdup ("");
+ grps->val[1] = xstrdup ("");
grps->group_defn = GROUPS_VALUES;
grps->val[0] =
grps->group_defn = GROUPS_VALUES;
grps->val[0] =
- strdup (gtk_entry_get_text (GTK_ENTRY (grps->grp_entry[0])));
+ xstrdup (gtk_entry_get_text (GTK_ENTRY (grps->grp_entry[0])));
- strdup (gtk_entry_get_text (GTK_ENTRY (grps->grp_entry[1])));
+ xstrdup (gtk_entry_get_text (GTK_ENTRY (grps->grp_entry[1])));
grps->val[1] = NULL;
grps->val[0] =
grps->val[1] = NULL;
grps->val[0] =
- strdup (gtk_entry_get_text (GTK_ENTRY (grps->cut_point_entry)));
+ xstrdup (gtk_entry_get_text (GTK_ENTRY (grps->cut_point_entry)));
}
psppire_dialog_notify_change (PSPPIRE_DIALOG (ttd->dialog));
}
psppire_dialog_notify_change (PSPPIRE_DIALOG (ttd->dialog));
/* PSPPIRE - a graphical user interface for PSPP.
/* PSPPIRE - a graphical user interface for PSPP.
- Copyright (C) 2007 Free Software Foundation
+ Copyright (C) 2007, 2009 Free Software Foundation
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
/* Create a GtkLabel and pack it into BOX.
The label is created using part of the string at S, and the directives
/* Create a GtkLabel and pack it into BOX.
The label is created using part of the string at S, and the directives
if ( 0 != printf_parse (fmt, &d, &a) )
return NULL;
if ( 0 != printf_parse (fmt, &d, &a) )
return NULL;
- widgets = calloc (sizeof (*widgets), d.count);
+ widgets = xcalloc (sizeof (*widgets), d.count);
va_start (ap, fmt);
for (i = 0 ; i < d.count ; ++i )
{
va_start (ap, fmt);
for (i = 0 ; i < d.count ; ++i )
{
/* PSPP - a program for statistical analysis.
/* PSPP - a program for statistical analysis.
- Copyright (C) 2007, 2008 Free Software Foundation, Inc.
+ Copyright (C) 2007, 2008, 2009 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
read_character_encoding (struct sfm_reader *r, size_t size, size_t count)
{
const unsigned long int posn = ftell (r->file);
read_character_encoding (struct sfm_reader *r, size_t size, size_t count)
{
const unsigned long int posn = ftell (r->file);
- char *encoding = calloc (size, count + 1);
+ char *encoding = xcalloc (size, count + 1);
read_string (r, encoding, count + 1);
printf ("%08lx: Character Encoding: %s\n", posn, encoding);
read_string (r, encoding, count + 1);
printf ("%08lx: Character Encoding: %s\n", posn, encoding);