From 07db00919d6f067fd5dd6c6c1c2c2fba4f42cf21 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 6 Aug 2009 21:45:38 -0700 Subject: [PATCH] Add CONST_CAST macro, for casting away "const" more safely. --- src/data/caseproto.c | 2 +- src/data/caseproto.h | 3 ++- src/data/casereader.c | 2 +- src/data/casewindow.c | 2 +- src/data/datasheet.c | 7 ++++--- src/data/dictionary.c | 4 ++-- src/data/procedure.c | 2 +- src/data/subcase.c | 2 +- src/data/value-labels.c | 6 ++++-- src/data/variable.c | 6 +++--- src/language/lexer/variable-parser.c | 4 ++-- src/language/xforms/count.c | 2 +- src/libpspp/abt.c | 13 +++++++------ src/libpspp/bt.c | 14 ++++++++------ src/libpspp/cast.h | 7 +++++++ src/libpspp/hash.h | 2 +- src/libpspp/ll.c | 18 +++++++++--------- src/libpspp/ll.h | 4 +++- src/libpspp/llx.c | 18 +++++++++--------- src/libpspp/range-set.c | 4 ++-- src/libpspp/range-set.h | 5 +++-- src/libpspp/sparse-array.c | 7 ++++--- src/libpspp/str.c | 3 ++- src/libpspp/taint.c | 13 +++++++------ src/libpspp/tmpfile.c | 5 +++-- src/libpspp/tower.c | 7 ++++--- src/math/percentiles.c | 2 +- src/output/chart.c | 2 +- tests/libpspp/range-set-test.c | 2 +- 29 files changed, 95 insertions(+), 73 deletions(-) diff --git a/src/data/caseproto.c b/src/data/caseproto.c index 1a40213a..9837013a 100644 --- a/src/data/caseproto.c +++ b/src/data/caseproto.c @@ -320,7 +320,7 @@ caseproto_free__ (struct caseproto *proto) void caseproto_refresh_long_string_cache__ (const struct caseproto *proto_) { - struct caseproto *proto = (struct caseproto *) proto_; + struct caseproto *proto = CONST_CAST (struct caseproto *, proto_); size_t n, i; assert (proto->long_strings == NULL); diff --git a/src/data/caseproto.h b/src/data/caseproto.h index b85a9f32..b0f45c41 100644 --- a/src/data/caseproto.h +++ b/src/data/caseproto.h @@ -22,6 +22,7 @@ #include #include #include +#include #include /* Case prototype. @@ -144,7 +145,7 @@ void caseproto_free__ (struct caseproto *); static inline struct caseproto * caseproto_ref (const struct caseproto *proto_) { - struct caseproto *proto = (struct caseproto *) proto_; + struct caseproto *proto = CONST_CAST (struct caseproto *, proto_); proto->ref_cnt++; return proto; } diff --git a/src/data/casereader.c b/src/data/casereader.c index a1550ac5..5ae5a0a8 100644 --- a/src/data/casereader.c +++ b/src/data/casereader.c @@ -108,7 +108,7 @@ casereader_destroy (struct casereader *reader) struct casereader * casereader_clone (const struct casereader *reader_) { - struct casereader *reader = (struct casereader *) reader_; + struct casereader *reader = CONST_CAST (struct casereader *, reader_); struct casereader *clone; if ( reader == NULL ) return NULL; diff --git a/src/data/casewindow.c b/src/data/casewindow.c index 9b04b941..936b6aa9 100644 --- a/src/data/casewindow.c +++ b/src/data/casewindow.c @@ -168,7 +168,7 @@ casewindow_pop_tail (struct casewindow *cw, casenumber case_cnt) struct ccase * casewindow_get_case (const struct casewindow *cw_, casenumber case_idx) { - struct casewindow *cw = (struct casewindow *) cw_; + struct casewindow *cw = CONST_CAST (struct casewindow *, cw_); assert (case_idx >= 0 && case_idx < casewindow_get_case_cnt (cw)); if (casewindow_error (cw)) diff --git a/src/data/datasheet.c b/src/data/datasheet.c index fa24d8ce..4abc526f 100644 --- a/src/data/datasheet.c +++ b/src/data/datasheet.c @@ -275,7 +275,7 @@ datasheet_destroy (struct datasheet *ds) const struct caseproto * datasheet_get_proto (const struct datasheet *ds_) { - struct datasheet *ds = (struct datasheet *) ds_; + struct datasheet *ds = CONST_CAST (struct datasheet *, ds_); if (ds->proto == NULL) { size_t i; @@ -548,7 +548,7 @@ datasheet_get_row (const struct datasheet *ds, casenumber row) { size_t n_columns = datasheet_get_n_columns (ds); struct ccase *c = case_create (datasheet_get_proto (ds)); - if (rw_case ((struct datasheet *) ds, OP_READ, + if (rw_case (CONST_CAST (struct datasheet *, ds), OP_READ, row, 0, n_columns, case_data_all_rw (c))) return c; else @@ -582,7 +582,8 @@ datasheet_get_value (const struct datasheet *ds, casenumber row, size_t column, union value *value) { assert (row >= 0); - return rw_case ((struct datasheet *) ds, OP_READ, row, column, 1, value); + return rw_case (CONST_CAST (struct datasheet *, ds), OP_READ, + row, column, 1, value); } /* Stores VALUE into DS in the given ROW and COLUMN. VALUE must diff --git a/src/data/dictionary.c b/src/data/dictionary.c index 67af049b..7379d194 100644 --- a/src/data/dictionary.c +++ b/src/data/dictionary.c @@ -1016,7 +1016,7 @@ dict_set_case_limit (struct dictionary *d, casenumber case_limit) const struct caseproto * dict_get_proto (const struct dictionary *d_) { - struct dictionary *d = (struct dictionary *) d_; + struct dictionary *d = CONST_CAST (struct dictionary *, d_); if (d->proto == NULL) { size_t i; @@ -1375,7 +1375,7 @@ dict_clear_vectors (struct dictionary *d) struct attrset * dict_get_attributes (const struct dictionary *d) { - return (struct attrset *) &d->attributes; + return CONST_CAST (struct attrset *, &d->attributes); } /* Replaces D's attributes set by a copy of ATTRS. */ diff --git a/src/data/procedure.c b/src/data/procedure.c index b762214d..5e013a14 100644 --- a/src/data/procedure.c +++ b/src/data/procedure.c @@ -682,7 +682,7 @@ dataset_end_of_command (struct dataset *ds) else { const struct taint *taint = casereader_get_taint (ds->source); - taint_reset_successor_taint ((struct taint *) taint); + taint_reset_successor_taint (CONST_CAST (struct taint *, taint)); assert (!taint_has_tainted_successor (taint)); } } diff --git a/src/data/subcase.c b/src/data/subcase.c index be586096..94831946 100644 --- a/src/data/subcase.c +++ b/src/data/subcase.c @@ -118,7 +118,7 @@ subcase_add_var (struct subcase *sc, const struct variable *var, const struct caseproto * subcase_get_proto (const struct subcase *sc_) { - struct subcase *sc = (struct subcase *) sc_; + struct subcase *sc = CONST_CAST (struct subcase *, sc_); if (sc->proto == NULL) { diff --git a/src/data/value-labels.c b/src/data/value-labels.c index c8061f7b..34223955 100644 --- a/src/data/value-labels.c +++ b/src/data/value-labels.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -169,7 +170,8 @@ void val_labs_replace (struct val_labs *vls, const union value *value, const char *label) { - struct val_lab *vl = (struct val_lab *) val_labs_lookup (vls, value); + struct val_lab *vl = CONST_CAST (struct val_lab *, + val_labs_lookup (vls, value)); if (vl != NULL) { atom_destroy (vl->label); @@ -183,7 +185,7 @@ val_labs_replace (struct val_labs *vls, const union value *value, void val_labs_remove (struct val_labs *vls, const struct val_lab *label_) { - struct val_lab *label = (struct val_lab *) label_; + struct val_lab *label = CONST_CAST (struct val_lab *, label_); hmap_delete (&vls->labels, &label->node); value_destroy (&label->value, vls->width); atom_destroy (label->label); diff --git a/src/data/variable.c b/src/data/variable.c index c0767d7c..bd0e8bf5 100644 --- a/src/data/variable.c +++ b/src/data/variable.c @@ -955,7 +955,7 @@ void * var_attach_aux (const struct variable *v_, void *aux, void (*aux_dtor) (struct variable *)) { - struct variable *v = (struct variable *) v_ ; /* cast away const */ + struct variable *v = CONST_CAST (struct variable *, v_); assert (v->aux == NULL); assert (aux != NULL); v->aux = aux; @@ -1013,7 +1013,7 @@ var_get_obs_vals (const struct variable *v) void var_set_obs_vals (const struct variable *v_, struct cat_vals *cat_vals) { - struct variable *v = (struct variable *) v_ ; /* cast away const */ + struct variable *v = CONST_CAST (struct variable *, v_ ); cat_stored_values_destroy (v->obs_vals); v->obs_vals = cat_vals; } @@ -1033,7 +1033,7 @@ var_has_obs_vals (const struct variable *v) struct attrset * var_get_attributes (const struct variable *v) { - return (struct attrset *) &v->attributes; + return CONST_CAST (struct attrset *, &v->attributes); } /* Replaces variable V's attributes set by a copy of ATTRS. */ diff --git a/src/language/lexer/variable-parser.c b/src/language/lexer/variable-parser.c index 1194110e..8a39dbf0 100644 --- a/src/language/lexer/variable-parser.c +++ b/src/language/lexer/variable-parser.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 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 @@ -757,7 +757,7 @@ array_var_set_get_var (const struct var_set *vs, size_t idx) { struct array_var_set *avs = vs->aux; - return (struct variable *) avs->var[idx]; + return CONST_CAST (struct variable *, avs->var[idx]); } /* If VS contains a variable named NAME, sets *IDX to its index diff --git a/src/language/xforms/count.c b/src/language/xforms/count.c index 8ce2d125..4fb889b1 100644 --- a/src/language/xforms/count.c +++ b/src/language/xforms/count.c @@ -352,7 +352,7 @@ count_trns_proc (void *trns_, struct ccase **c, static bool count_trns_free (void *trns_) { - struct count_trns *trns = (struct count_trns *) trns_; + struct count_trns *trns = trns_; pool_destroy (trns->pool); return true; } diff --git a/src/libpspp/abt.c b/src/libpspp/abt.c index 74b2ceb3..b7766129 100644 --- a/src/libpspp/abt.c +++ b/src/libpspp/abt.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 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 @@ -29,6 +29,7 @@ #endif #include +#include #include @@ -145,8 +146,8 @@ insert_relative (struct abt *abt, const struct abt_node *p, bool after, p = p->down[dir]; dir = !after; } - ((struct abt_node *) p)->down[dir] = node; - node->up = (struct abt_node *) p; + CONST_CAST (struct abt_node *, p)->down[dir] = node; + node->up = CONST_CAST (struct abt_node *, p); abt_reaugmented (abt, node); } @@ -280,7 +281,7 @@ abt_find (const struct abt *abt, const struct abt_node *target) { cmp = abt->compare (target, p, abt->aux); if (cmp == 0) - return (struct abt_node *) p; + return CONST_CAST (struct abt_node *, p); } return NULL; @@ -307,7 +308,7 @@ abt_next (const struct abt *abt, const struct abt_node *p) p = p->down[1]; while (p->down[0] != NULL) p = p->down[0]; - return (struct abt_node *) p; + return CONST_CAST (struct abt_node *, p); } } @@ -332,7 +333,7 @@ abt_prev (const struct abt *abt, const struct abt_node *p) p = p->down[0]; while (p->down[1] != NULL) p = p->down[1]; - return (struct abt_node *) p; + return CONST_CAST (struct abt_node *, p); } } diff --git a/src/libpspp/bt.c b/src/libpspp/bt.c index 26eb982b..751c8fe7 100644 --- a/src/libpspp/bt.c +++ b/src/libpspp/bt.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 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 @@ -67,6 +67,8 @@ #include #include +#include + static void rebalance_subtree (struct bt *, struct bt_node *, size_t); static struct bt_node **down_link (struct bt *, struct bt_node *); @@ -250,7 +252,7 @@ bt_find (const struct bt *bt, const struct bt_node *target) { cmp = bt->compare (target, p, bt->aux); if (cmp == 0) - return (struct bt_node *) p; + return CONST_CAST (struct bt_node *, p); } return NULL; @@ -283,7 +285,7 @@ bt_find_ge (const struct bt *bt, const struct bt_node *target) break; } } - return (struct bt_node *) q; + return CONST_CAST (struct bt_node *, q); } /* Searches BT for, and returns, the last node in in-order whose @@ -314,7 +316,7 @@ bt_find_le (const struct bt *bt, const struct bt_node *target) break; } } - return (struct bt_node *) q; + return CONST_CAST (struct bt_node *, q); } /* Returns the node in BT following P in in-order. @@ -338,7 +340,7 @@ bt_next (const struct bt *bt, const struct bt_node *p) p = p->down[1]; while (p->down[0] != NULL) p = p->down[0]; - return (struct bt_node *) p; + return CONST_CAST (struct bt_node *, p); } } @@ -363,7 +365,7 @@ bt_prev (const struct bt *bt, const struct bt_node *p) p = p->down[0]; while (p->down[1] != NULL) p = p->down[1]; - return (struct bt_node *) p; + return CONST_CAST (struct bt_node *, p); } } diff --git a/src/libpspp/cast.h b/src/libpspp/cast.h index 30927899..1e33857c 100644 --- a/src/libpspp/cast.h +++ b/src/libpspp/cast.h @@ -76,6 +76,13 @@ above, can easily be devised. */ #define CHECK_POINTER_COMPATIBILITY(A, B) ((void) sizeof ((A) == (B))) +/* Equivalent to casting POINTER to TYPE, but also issues a + warning if the cast changes anything other than an outermost + "const" or "volatile" qualifier. */ +#define CONST_CAST(TYPE, POINTER) \ + (CHECK_POINTER_HAS_TYPE (POINTER, TYPE), \ + (TYPE) (POINTER)) + /* Given POINTER, a pointer to the given MEMBER within structure STRUCT, returns the address of the STRUCT. */ #define UP_CAST(POINTER, STRUCT, MEMBER) \ diff --git a/src/libpspp/hash.h b/src/libpspp/hash.h index 57fc2678..e586bcc0 100644 --- a/src/libpspp/hash.h +++ b/src/libpspp/hash.h @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 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 diff --git a/src/libpspp/ll.c b/src/libpspp/ll.c index b9d595bc..e6533f2c 100644 --- a/src/libpspp/ll.c +++ b/src/libpspp/ll.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 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 @@ -169,7 +169,7 @@ ll_find_equal (const struct ll *r0, const struct ll *r1, for (x = r0; x != r1; x = ll_next (x)) if (compare (x, target, aux) == 0) break; - return (struct ll *) x; + return CONST_CAST (struct ll *, x); } /* Returns the first node in R0...R1 for which PREDICATE returns @@ -185,7 +185,7 @@ ll_find_if (const struct ll *r0, const struct ll *r1, for (x = r0; x != r1; x = ll_next (x)) if (predicate (x, aux)) break; - return (struct ll *) x; + return CONST_CAST (struct ll *, x); } /* Compares each pair of adjacent nodes in R0...R1 @@ -203,10 +203,10 @@ ll_find_adjacent_equal (const struct ll *r0, const struct ll *r1, for (x = r0, y = ll_next (x); y != r1; x = y, y = ll_next (y)) if (compare (x, y, aux) == 0) - return (struct ll *) x; + return CONST_CAST (struct ll *, x); } - return (struct ll *) r1; + return CONST_CAST (struct ll *, r1); } /* Returns the number of nodes in R0...R1. @@ -272,7 +272,7 @@ ll_max (const struct ll *r0, const struct ll *r1, if (compare (x, max, aux) > 0) max = x; } - return (struct ll *) max; + return CONST_CAST (struct ll *, max); } /* Returns the least node in R0...R1 according to COMPARE given @@ -291,7 +291,7 @@ ll_min (const struct ll *r0, const struct ll *r1, if (compare (x, min, aux) < 0) min = x; } - return (struct ll *) min; + return CONST_CAST (struct ll *, min); } /* Lexicographically compares A0...A1 to B0...B1. @@ -474,7 +474,7 @@ ll_find_run (const struct ll *r0, const struct ll *r1, while (r0 != r1 && compare (ll_prev (r0), r0, aux) <= 0); } - return (struct ll *) r0; + return CONST_CAST (struct ll *, r0); } /* Merges B0...B1 into A0...A1 according to COMPARE given @@ -681,6 +681,6 @@ ll_find_partition (const struct ll *r0, const struct ll *r1, if (predicate (x, aux)) return NULL; - return (struct ll *) partition; + return CONST_CAST (struct ll *, partition); } diff --git a/src/libpspp/ll.h b/src/libpspp/ll.h index 4d0d2eb8..bf871f6b 100644 --- a/src/libpspp/ll.h +++ b/src/libpspp/ll.h @@ -52,6 +52,8 @@ #include #include +#include + /* Embedded, circular doubly linked list. Each list contains a single "null" element that separates the @@ -380,7 +382,7 @@ ll_tail (const struct ll_list *list) static inline struct ll * ll_null (const struct ll_list *list) { - return (struct ll *) &list->null; + return CONST_CAST (struct ll *, &list->null); } /* Returns the node following LL in its list, diff --git a/src/libpspp/llx.c b/src/libpspp/llx.c index 4dc82bff..c58f840c 100644 --- a/src/libpspp/llx.c +++ b/src/libpspp/llx.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 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 @@ -232,7 +232,7 @@ llx_find_equal (const struct llx *r0, const struct llx *r1, for (x = r0; x != r1; x = llx_next (x)) if (compare (llx_data (x), target, aux) == 0) break; - return (struct llx *) x; + return CONST_CAST (struct llx *, x); } /* Returns the first node in R0...R1 for which PREDICATE returns @@ -248,7 +248,7 @@ llx_find_if (const struct llx *r0, const struct llx *r1, for (x = r0; x != r1; x = llx_next (x)) if (predicate (llx_data (x), aux)) break; - return (struct llx *) x; + return CONST_CAST (struct llx *, x); } /* Compares each pair of adjacent nodes in R0...R1 @@ -266,10 +266,10 @@ llx_find_adjacent_equal (const struct llx *r0, const struct llx *r1, for (x = r0, y = llx_next (x); y != r1; x = y, y = llx_next (y)) if (compare (llx_data (x), llx_data (y), aux) == 0) - return (struct llx *) x; + return CONST_CAST (struct llx *, x); } - return (struct llx *) r1; + return CONST_CAST (struct llx *, r1); } /* Returns the number of nodes in R0...R1. @@ -329,7 +329,7 @@ llx_max (const struct llx *r0, const struct llx *r1, if (compare (llx_data (x), llx_data (max), aux) > 0) max = x; } - return (struct llx *) max; + return CONST_CAST (struct llx *, max); } /* Returns the least node in R0...R1 according to COMPARE given @@ -348,7 +348,7 @@ llx_min (const struct llx *r0, const struct llx *r1, if (compare (llx_data (x), llx_data (min), aux) < 0) min = x; } - return (struct llx *) min; + return CONST_CAST (struct llx *, min); } /* Lexicographically compares A0...A1 to B0...B1. @@ -521,7 +521,7 @@ llx_find_run (const struct llx *r0, const struct llx *r1, llx_data (r0), aux) <= 0); } - return (struct llx *) r0; + return CONST_CAST (struct llx *, r0); } /* Merges B0...B1 into A0...A1 according to COMPARE given @@ -734,7 +734,7 @@ llx_find_partition (const struct llx *r0, const struct llx *r1, if (predicate (llx_data (x), aux)) return NULL; - return (struct llx *) partition; + return CONST_CAST (struct llx *, partition); } /* Allocates and returns a node using malloc. */ diff --git a/src/libpspp/range-set.c b/src/libpspp/range-set.c index efa3b4d6..cd17fe02 100644 --- a/src/libpspp/range-set.c +++ b/src/libpspp/range-set.c @@ -287,7 +287,7 @@ range_set_allocate_fully (struct range_set *rs, unsigned long int request, bool range_set_contains (const struct range_set *rs_, unsigned long int position) { - struct range_set *rs = (struct range_set *) rs_; + struct range_set *rs = CONST_CAST (struct range_set *, rs_); if (position < rs->cache_end && position >= rs->cache_start) return rs->cache_value; else @@ -328,7 +328,7 @@ range_set_contains (const struct range_set *rs_, unsigned long int position) unsigned long int range_set_scan (const struct range_set *rs_, unsigned long int start) { - struct range_set *rs = (struct range_set *) rs_; + struct range_set *rs = CONST_CAST (struct range_set *, rs_); unsigned long int retval = ULONG_MAX; struct bt_node *bt_node; diff --git a/src/libpspp/range-set.h b/src/libpspp/range-set.h index 941692b4..ee7dac23 100644 --- a/src/libpspp/range-set.h +++ b/src/libpspp/range-set.h @@ -26,6 +26,7 @@ #include #include +#include /* A set of ranges. */ struct range_set @@ -122,7 +123,7 @@ static inline const struct range_set_node * range_set_next (const struct range_set *rs, const struct range_set_node *node) { return (node != NULL - ? range_set_next__ (rs, (struct range_set_node *) node) + ? range_set_next__ (rs, CONST_CAST (struct range_set_node *, node)) : range_set_first__ (rs)); } @@ -147,7 +148,7 @@ static inline const struct range_set_node * range_set_prev (const struct range_set *rs, const struct range_set_node *node) { return (node != NULL - ? range_set_prev__ (rs, (struct range_set_node *) node) + ? range_set_prev__ (rs, CONST_CAST (struct range_set_node *, node)) : range_set_last__ (rs)); } diff --git a/src/libpspp/sparse-array.c b/src/libpspp/sparse-array.c index 28398d5c..298f2caf 100644 --- a/src/libpspp/sparse-array.c +++ b/src/libpspp/sparse-array.c @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -577,7 +578,7 @@ leaf_size (const struct sparse_array *spar) static struct leaf_node * find_leaf_node (const struct sparse_array *spar_, unsigned long int key) { - struct sparse_array *spar = (struct sparse_array *) spar_; + struct sparse_array *spar = CONST_CAST (struct sparse_array *, spar_); const union pointer *p; int level; @@ -679,7 +680,7 @@ static void * scan_forward (const struct sparse_array *spar_, unsigned long int start, unsigned long int *found) { - struct sparse_array *spar = (struct sparse_array *) spar_; + struct sparse_array *spar = CONST_CAST (struct sparse_array *, spar_); /* Check the cache. */ if (start >> BITS_PER_LEVEL == spar->cache_ofs) @@ -761,7 +762,7 @@ static void * scan_reverse (const struct sparse_array *spar_, unsigned long int start, unsigned long int *found) { - struct sparse_array *spar = (struct sparse_array *) spar_; + struct sparse_array *spar = CONST_CAST (struct sparse_array *, spar_); /* Check the cache. */ if (start >> BITS_PER_LEVEL == spar->cache_ofs) diff --git a/src/libpspp/str.c b/src/libpspp/str.c index ccd7739c..c954a722 100644 --- a/src/libpspp/str.c +++ b/src/libpspp/str.c @@ -23,6 +23,7 @@ #include #include +#include #include #include @@ -1214,7 +1215,7 @@ ds_capacity (const struct string *st) char * ds_cstr (const struct string *st_) { - struct string *st = (struct string *) st_; + struct string *st = CONST_CAST (struct string *, st_); if (st->ss.string == NULL) ds_extend (st, 1); st->ss.string[st->ss.length] = '\0'; diff --git a/src/libpspp/taint.c b/src/libpspp/taint.c index 3a74587b..4c1cecb9 100644 --- a/src/libpspp/taint.c +++ b/src/libpspp/taint.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 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 @@ -22,6 +22,7 @@ #include #include +#include #include "xalloc.h" @@ -79,7 +80,7 @@ taint_create (void) struct taint * taint_clone (const struct taint *taint_) { - struct taint *taint = (struct taint *) taint_; + struct taint *taint = CONST_CAST (struct taint *, taint_); assert (taint->ref_cnt > 0); taint->ref_cnt++; @@ -139,8 +140,8 @@ taint_destroy (struct taint *taint) void taint_propagate (const struct taint *from_, const struct taint *to_) { - struct taint *from = (struct taint *) from_; - struct taint *to = (struct taint *) to_; + struct taint *from = CONST_CAST (struct taint *, from_); + struct taint *to = CONST_CAST (struct taint *, to_); if (from != to) { @@ -165,7 +166,7 @@ taint_is_tainted (const struct taint *taint) void taint_set_taint (const struct taint *taint_) { - struct taint *taint = (struct taint *) taint_; + struct taint *taint = CONST_CAST (struct taint *, taint_); if (!taint->tainted) recursively_set_taint (taint); } @@ -186,7 +187,7 @@ taint_has_tainted_successor (const struct taint *taint) void taint_reset_successor_taint (const struct taint *taint_) { - struct taint *taint = (struct taint *) taint_; + struct taint *taint = CONST_CAST (struct taint *, taint_); if (taint->tainted_successor) { diff --git a/src/libpspp/tmpfile.c b/src/libpspp/tmpfile.c index 0d309364..aff135d0 100644 --- a/src/libpspp/tmpfile.c +++ b/src/libpspp/tmpfile.c @@ -26,6 +26,7 @@ #include #include +#include #include "error.h" #include "xalloc.h" @@ -81,7 +82,7 @@ tmpfile_destroy (struct tmpfile *tf) static bool do_seek (const struct tmpfile *tf_, off_t offset) { - struct tmpfile *tf = (struct tmpfile *) tf_; + struct tmpfile *tf = CONST_CAST (struct tmpfile *, tf_); if (!tmpfile_error (tf)) { @@ -106,7 +107,7 @@ do_seek (const struct tmpfile *tf_, off_t offset) static bool do_read (const struct tmpfile *tf_, void *buffer, size_t bytes) { - struct tmpfile *tf = (struct tmpfile *) tf_; + struct tmpfile *tf = CONST_CAST (struct tmpfile *, tf_); assert (!tmpfile_error (tf)); if (bytes > 0 && fread (buffer, bytes, 1, tf->file) != 1) diff --git a/src/libpspp/tower.c b/src/libpspp/tower.c index e8d253d0..91579877 100644 --- a/src/libpspp/tower.c +++ b/src/libpspp/tower.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 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 @@ -21,6 +21,7 @@ #include #include +#include #include static struct tower_node *abt_to_tower_node (const struct abt_node *); @@ -184,7 +185,7 @@ tower_lookup (const struct tower *t_, unsigned long height, unsigned long *node_start) { - struct tower *t = (struct tower *) t_; + struct tower *t = CONST_CAST (struct tower *, t_); struct abt_node *p; assert (height < tower_height (t)); @@ -237,7 +238,7 @@ tower_lookup (const struct tower *t_, struct tower_node * tower_get (const struct tower *t_, unsigned long int index) { - struct tower *t = (struct tower *) t_; + struct tower *t = CONST_CAST (struct tower *, t_); struct abt_node *p; assert (index < tower_count (t)); diff --git a/src/math/percentiles.c b/src/math/percentiles.c index 2bde9d6f..c76bb492 100644 --- a/src/math/percentiles.c +++ b/src/math/percentiles.c @@ -45,7 +45,7 @@ const char *const ptile_alg_desc[] = { double percentile_calculate (const struct percentile *ptl, enum pc_alg alg) { - struct percentile *mutable = (struct percentile *) ptl; + struct percentile *mutable = CONST_CAST (struct percentile *, ptl); const struct order_stats *os = &ptl->parent; assert (os->cc == ptl->w); diff --git a/src/output/chart.c b/src/output/chart.c index e1832e20..1f85d8e4 100644 --- a/src/output/chart.c +++ b/src/output/chart.c @@ -142,7 +142,7 @@ chart_draw_png (const struct chart *chart, const char *file_name_template, struct chart * chart_ref (const struct chart *chart_) { - struct chart *chart = (struct chart *) chart_; + struct chart *chart = CONST_CAST (struct chart *, chart_); chart->ref_cnt++; return chart; } diff --git a/tests/libpspp/range-set-test.c b/tests/libpspp/range-set-test.c index e8cbffa5..8d6e6831 100644 --- a/tests/libpspp/range-set-test.c +++ b/tests/libpspp/range-set-test.c @@ -212,7 +212,7 @@ check_pattern (const struct range_set *rs, unsigned int pattern) caching. */ for (start = 0; start <= 32; start++) { - struct range_set *nonconst_rs = (struct range_set *) rs; + struct range_set *nonconst_rs = CONST_CAST (struct range_set *, rs); nonconst_rs->cache_end = 0; s1 = range_set_scan (rs, start); s2 = next_1bit (pattern, start); -- 2.30.2