From: Ben Pfaff Date: Thu, 16 Jun 2011 06:08:13 +0000 (-0700) Subject: Update code that assumed a dictionary's encoding could be NULL. X-Git-Tag: v0.7.9~279 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bb0bebf8612a24fc5b58d0a85ff90ddb6d3f9e7a;p=pspp-builds.git Update code that assumed a dictionary's encoding could be NULL. Until recently, I think, it was possible for dict_get_encoding() to return NULL. It is no longer possible as far as I can see, so this commit adds a comment that says so to the definition of dict_get_encoding(). It also updates a few callers that had checks for null pointers. --- diff --git a/src/data/csv-file-writer.c b/src/data/csv-file-writer.c index 11b7429c..cbc617b3 100644 --- a/src/data/csv-file-writer.c +++ b/src/data/csv-file-writer.c @@ -122,9 +122,7 @@ csv_writer_open (struct file_handle *fh, const struct dictionary *dict, w->opts = *opts; - w->encoding = (dict_get_encoding (dict) - ? xstrdup (dict_get_encoding (dict)) - : NULL); + w->encoding = xstrdup (dict_get_encoding (dict)); w->n_csv_vars = dict_get_var_cnt (dict); w->csv_vars = xnmalloc (w->n_csv_vars, sizeof *w->csv_vars); diff --git a/src/data/dictionary.c b/src/data/dictionary.c index 4a0afc73..2d99f6d7 100644 --- a/src/data/dictionary.c +++ b/src/data/dictionary.c @@ -87,6 +87,8 @@ struct dictionary static void dict_unset_split_var (struct dictionary *, struct variable *); static void dict_unset_mrset_var (struct dictionary *, struct variable *); +/* Returns the encoding for data in dictionary D. The return value is a + nonnull string that contains an IANA character set name. */ const char * dict_get_encoding (const struct dictionary *d) { @@ -194,8 +196,7 @@ dict_clone (const struct dictionary *s) /* Set the new dictionary's encoding early so that string length limitations are interpreted correctly. */ - if ( s->encoding) - d->encoding = xstrdup (s->encoding); + d->encoding = xstrdup (s->encoding); for (i = 0; i < s->var_cnt; i++) { diff --git a/src/data/sys-file-writer.c b/src/data/sys-file-writer.c index aeb97d64..5ebf3ede 100644 --- a/src/data/sys-file-writer.c +++ b/src/data/sys-file-writer.c @@ -851,22 +851,18 @@ static void write_encoding_record (struct sfm_writer *w, const struct dictionary *d) { - if (dict_get_encoding (d) != NULL) - { - /* IANA says "...character set names may be up to 40 characters taken - from the printable characters of US-ASCII," so character set names - don't need to be recoded to be in UTF-8. - - We convert encoding names to uppercase because SPSS writes encoding - names in uppercase. */ - char *encoding = xstrdup (dict_get_encoding (d)); - str_uppercase (encoding); - write_string_record (w, ss_cstr (encoding), 20); - free (encoding); - } + /* IANA says "...character set names may be up to 40 characters taken + from the printable characters of US-ASCII," so character set names + don't need to be recoded to be in UTF-8. + + We convert encoding names to uppercase because SPSS writes encoding + names in uppercase. */ + char *encoding = xstrdup (dict_get_encoding (d)); + str_uppercase (encoding); + write_string_record (w, ss_cstr (encoding), 20); + free (encoding); } - /* Writes the long variable name table. */ static void write_longvar_table (struct sfm_writer *w, const struct dictionary *dict) diff --git a/src/language/dictionary/sys-file-info.c b/src/language/dictionary/sys-file-info.c index 27b27858..59632951 100644 --- a/src/language/dictionary/sys-file-info.c +++ b/src/language/dictionary/sys-file-info.c @@ -138,8 +138,7 @@ cmd_sysfile_info (struct lexer *lexer, struct dataset *ds UNUSED) tab_text (t, 0, 10, TAB_LEFT, _("Charset:")); - tab_text (t, 1, 10, TAB_LEFT, - dict_get_encoding(d) ? dict_get_encoding(d) : _("Unknown")); + tab_text (t, 1, 10, TAB_LEFT, dict_get_encoding (d)); tab_submit (t);