Const casts.
authorJohn Darrington <john@darrington.wattle.id.au>
Sun, 19 Sep 2010 14:36:57 +0000 (16:36 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Sun, 19 Sep 2010 14:36:57 +0000 (16:36 +0200)
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
src/language/lexer/q2c.c
src/language/stats/autorecode.c
src/language/tests/float-format.c
src/libpspp/str.c
src/output/ascii.c
src/output/options.c
src/ui/gui/main.c
src/ui/terminal/terminal-opts.c

index 68ea7e5672cea1c483fb356e75b5834852642c1d..b86cf4ed6cbdf483fdc861db0e644514537a0d90 100644 (file)
@@ -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;
 
index f2617092b3368c6173a4676ee549b3bf7cb320d5..1a95d08091936461b083a35b3d27531d3795151e 100644 (file)
@@ -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
index a18a94c6bd5fa5514a7fb69e43ac5a58e4f1697c..ce818cff1169f7e2fd61a15d926942fe405474ca 100644 (file)
@@ -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
index fed19479d2fe8043ee1a060e88b49b2fc4221c3e..b2d5a1663f0808a8a6b9a6f09a3527eea61c3b24 100644 (file)
@@ -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);
index 71f54474d57f995f8c5b73572e1d8f761b7e934e..bde4de4be5bb4ee13edf877e217537336debfc0a 100644 (file)
@@ -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));
     }
 }
 
index 6afefefa0ef15d9b8d328b1055759432b3bd7d8c..12cde8e5f2f8b18722d1fd0bc0988896900cac69 100644 (file)
@@ -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));
 
index 11d38ea4679b0aba5f3cab97ac59f9b2428cebd6..e0259f0936246e9f5f49a184de9239176eaf57e6 100644 (file)
@@ -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. */
index a5e054f02d527d21020257f015eebea1b2b0b2a3..a78d248aeb38e0301e8706455e4767f0856a9255 100644 (file)
@@ -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:
index bfda71e66cd2e9dc3750721d1200a5cfd955820f..929fd3878defb8c4f0a02b3f70982d1cc4ec7c8c 100644 (file)
@@ -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: