From: John Darrington Date: Sun, 19 Sep 2010 14:36:57 +0000 (+0200) Subject: Const casts. X-Git-Tag: sav-api~33 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pspp;a=commitdiff_plain;h=c75794cffb05769b71a346af8513a3e8dde55f94 Const casts. Removed some unnecessary casts. Changed some others to use the macros from src/libpspp/cast.h instead of literal casts. --- diff --git a/src/data/psql-reader.c b/src/data/psql-reader.c index 68ea7e5672..b86cf4ed6c 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 f2617092b3..1a95d08091 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 a18a94c6bd..ce818cff11 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 fed19479d2..b2d5a1663f 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 71f54474d5..bde4de4be5 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 6afefefa0e..12cde8e5f2 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 11d38ea467..e0259f0936 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 a5e054f02d..a78d248aeb 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 bfda71e66c..929fd3878d 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: