From c75794cffb05769b71a346af8513a3e8dde55f94 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Sun, 19 Sep 2010 16:36:57 +0200 Subject: [PATCH] Const casts. Removed some unnecessary casts. Changed some others to use the macros from src/libpspp/cast.h instead of literal casts. --- src/data/psql-reader.c | 2 +- src/language/lexer/q2c.c | 4 ++-- src/language/stats/autorecode.c | 6 +++--- src/language/tests/float-format.c | 2 +- src/libpspp/str.c | 4 +++- src/output/ascii.c | 2 +- src/output/options.c | 2 +- src/ui/gui/main.c | 2 +- src/ui/terminal/terminal-opts.c | 2 +- 9 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/data/psql-reader.c b/src/data/psql-reader.c index 68ea7e56..b86cf4ed 100644 --- a/src/data/psql-reader.c +++ b/src/data/psql-reader.c @@ -838,7 +838,7 @@ set_value (struct psql_reader *r) case VARCHAROID: case BPCHAROID: case BYTEAOID: - memcpy (value_str_rw (val, var_width), (char *) vptr, + memcpy (value_str_rw (val, var_width), vptr, MIN (length, var_width)); break; diff --git a/src/language/lexer/q2c.c b/src/language/lexer/q2c.c index f2617092..1a95d080 100644 --- a/src/language/lexer/q2c.c +++ b/src/language/lexer/q2c.c @@ -225,11 +225,11 @@ st_upper (const char *s) /* Returns the address of the first non-whitespace character in S, or the address of the null terminator if none. */ static char * -skip_ws (const char *s) +skip_ws (char *s) { while (isspace ((unsigned char) *s)) s++; - return (char *) s; + return s; } /* Read one line from the input file into buf. Lines having special diff --git a/src/language/stats/autorecode.c b/src/language/stats/autorecode.c index a18a94c6..ce818cff 100644 --- a/src/language/stats/autorecode.c +++ b/src/language/stats/autorecode.c @@ -248,7 +248,7 @@ cmd_autorecode (struct lexer *lexer, struct dataset *ds) the source value from whence the new value comes. */ if (src_width > 0) { - const char *str = (const char *) value_str (from, src_width); + const char *str = CHAR_CAST_BUG (const char*, value_str (from, src_width)); recoded_value = recode_string (UTF8, dict_get_encoding (dict), str, src_width); } @@ -357,8 +357,8 @@ compare_arc_items (const void *a_, const void *b_, const void *aux UNUSED) if ( width_b == 0 && width_a != 0) return +1; - return buf_compare_rpad ((const char *) value_str (&(*a)->from, width_a), width_a, - (const char *) value_str (&(*b)->from, width_b), width_b); + return buf_compare_rpad (CHAR_CAST_BUG (const char *, value_str (&(*a)->from, width_a)), width_a, + CHAR_CAST_BUG (const char *, value_str (&(*b)->from, width_b)), width_b); } static int diff --git a/src/language/tests/float-format.c b/src/language/tests/float-format.c index fed19479..b2d5a166 100644 --- a/src/language/tests/float-format.c +++ b/src/language/tests/float-format.c @@ -136,7 +136,7 @@ parse_fp (struct lexer *lexer, struct fp *fp) msg (SE, _("Hexadecimal floating constant too long.")); return false; } - strncpy ((char *) fp->data, ds_cstr (lex_tokstr (lexer)), sizeof fp->data); + strncpy (CHAR_CAST_BUG (char *,fp->data), ds_cstr (lex_tokstr (lexer)), sizeof fp->data); } lex_get (lexer); diff --git a/src/libpspp/str.c b/src/libpspp/str.c index 71f54474..bde4de4b 100644 --- a/src/libpspp/str.c +++ b/src/libpspp/str.c @@ -1465,7 +1465,9 @@ ds_relocate (struct string *st) { ds_clear (st); ds_put_cstr (st, rel); - free ((char *) rel); + /* The documentation for relocate says that casting away const + and then freeing is appropriate ... */ + free (CONST_CAST (char *, rel)); } } diff --git a/src/output/ascii.c b/src/output/ascii.c index 6afefefa..12cde8e5 100644 --- a/src/output/ascii.c +++ b/src/output/ascii.c @@ -184,7 +184,7 @@ ascii_create (const char *file_name, enum settings_output_devices device_type, "bold", EMPH_BOLD, "underline", EMPH_UNDERLINE, "none", EMPH_NONE, - (char *) NULL); + NULL); a->chart_file_name = parse_chart_file_name (opt (d, o, "charts", file_name)); diff --git a/src/output/options.c b/src/output/options.c index 11d38ea4..e0259f09 100644 --- a/src/output/options.c +++ b/src/output/options.c @@ -145,7 +145,7 @@ parse_boolean (struct driver_option *o) O has no user-specified value, then O's default value is treated the same way. If the default value still does not match, parse_enum() returns 0. - Example: parse_enum (o, "a", 1, "b", 2, (char *) NULL) returns 1 if O's + Example: parse_enum (o, "a", 1, "b", 2, NULL) returns 1 if O's value if "a", 2 if O's value is "b". Destroys O. */ diff --git a/src/ui/gui/main.c b/src/ui/gui/main.c index a5e054f0..a78d248a 100644 --- a/src/ui/gui/main.c +++ b/src/ui/gui/main.c @@ -145,7 +145,7 @@ startup_option_callback (int id, void *show_splash_) case OPT_VERSION: version_etc (stdout, "psppire", PACKAGE_NAME, PACKAGE_VERSION, "Ben Pfaff", "John Darrington", "Jason Stover", - (char *) NULL); + NULL); exit (EXIT_SUCCESS); case OPT_NO_SPLASH: diff --git a/src/ui/terminal/terminal-opts.c b/src/ui/terminal/terminal-opts.c index bfda71e6..929fd387 100644 --- a/src/ui/terminal/terminal-opts.c +++ b/src/ui/terminal/terminal-opts.c @@ -273,7 +273,7 @@ terminal_option_callback (int id, void *to_) case OPT_VERSION: version_etc (stdout, "pspp", PACKAGE_NAME, PACKAGE_VERSION, "Ben Pfaff", "John Darrington", "Jason Stover", - (char *) NULL); + NULL); exit (EXIT_SUCCESS); default: -- 2.30.2