From: Ben Pfaff Date: Mon, 24 Oct 2005 02:51:28 +0000 (+0000) Subject: Work to get rid of GCC 4.0 warnings, part 1. X-Git-Tag: v0.6.0~1179 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6eea9310493902d3b06b25c612c7ba89d467b6fa;p=pspp-builds.git Work to get rid of GCC 4.0 warnings, part 1. In many files, change count parameters to parse_variables(), etc. from `int' to `size_t'. Also change related variables and struct members. Also change messages as needed (e.g. %d to %u with cast to unsigned). Also change arithmetic as necessary (e.g. n >= m - 1 to n + 1 >= m). --- diff --git a/src/ChangeLog b/src/ChangeLog index bf314324..4fd66f6f 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,19 @@ +Sun Oct 23 19:28:08 2005 Ben Pfaff + + Work to get rid of GCC 4.0 warnings, part 1. + + In many files, change count parameters to parse_variables(), + etc. from `int' to `size_t'. Also change related variables and + struct members. Also change messages as needed (e.g. %d to %u + with cast to unsigned). Also change arithmetic as necessary + (e.g. n >= m - 1 to n + 1 >= m). + + * crosstabs.q: (crs_custom_tables) Check for size_t overflow in + multiplication. + + * q2c.c: (dump_declarations) Generate code for size_t instead of + int. + Thu Oct 20 18:18:40 2005 Ben Pfaff * output.c: (outp_read_devices) Fix message. diff --git a/src/aggregate.c b/src/aggregate.c index 5979204d..91d7d9bd 100644 --- a/src/aggregate.c +++ b/src/aggregate.c @@ -77,7 +77,7 @@ enum struct agr_func { const char *name; /* Aggregation function name. */ - int n_args; /* Number of arguments. */ + size_t n_args; /* Number of arguments. */ int alpha_type; /* When given ALPHA arguments, output type. */ struct fmt_spec format; /* Format spec if alpha_type != ALPHA. */ }; @@ -336,7 +336,7 @@ parse_aggregate_functions (struct agr_proc *agr) { char **dest; char **dest_label; - int n_dest; + size_t n_dest; int include_missing; const struct agr_func *function; @@ -345,9 +345,9 @@ parse_aggregate_functions (struct agr_proc *agr) union value arg[2]; struct variable **src; - int n_src; + size_t n_src; - int i; + size_t i; dest = NULL; dest_label = NULL; @@ -361,7 +361,7 @@ parse_aggregate_functions (struct agr_proc *agr) /* Parse the list of target variables. */ while (!lex_match ('=')) { - int n_dest_prev = n_dest; + size_t n_dest_prev = n_dest; if (!parse_DATA_LIST_vars (&dest, &n_dest, PV_APPEND | PV_SINGLE | PV_NO_SCRATCH)) @@ -486,9 +486,9 @@ parse_aggregate_functions (struct agr_proc *agr) like `unknown variable t'. */ if (n_src != n_dest) { - msg (SE, _("Number of source variables (%d) does not match " - "number of target variables (%d)."), - n_src, n_dest); + msg (SE, _("Number of source variables (%u) does not match " + "number of target variables (%u)."), + (unsigned) n_src, (unsigned) n_dest); goto error; } @@ -663,8 +663,8 @@ agr_destroy (struct agr_proc *agr) if (iter->function & FSTRING) { - int n_args; - int i; + size_t n_args; + size_t i; n_args = agr_func_tab[iter->function & FUNC].n_args; for (i = 0; i < n_args; i++) diff --git a/src/autorecode.c b/src/autorecode.c index 1f0fd8a3..619d894e 100644 --- a/src/autorecode.c +++ b/src/autorecode.c @@ -58,7 +58,7 @@ struct autorecode_trns struct trns_header h; struct pool *owner; /* Contains AUTORECODE specs. */ struct arc_spec *specs; /* AUTORECODE specifications. */ - int spec_cnt; /* Number of specifications. */ + size_t spec_cnt; /* Number of specifications. */ }; /* Descending or ascending sort order. */ @@ -75,7 +75,7 @@ struct autorecode_pgm char **dst_names; /* Target variable names. */ struct variable **dst_vars; /* Target variables. */ struct hsh_table **src_values; /* `union value's of source vars. */ - int var_cnt; /* Number of variables. */ + size_t var_cnt; /* Number of variables. */ struct pool *src_values_pool; /* Pool used by src_values. */ enum direction direction; /* Sort order. */ int print; /* Print mapping table if nonzero. */ @@ -95,8 +95,8 @@ int cmd_autorecode (void) { struct autorecode_pgm arc; - int dst_cnt; - int i; + size_t dst_cnt; + size_t i; arc.src_vars = NULL; arc.dst_names = NULL; @@ -120,10 +120,11 @@ cmd_autorecode (void) goto lossage; if (dst_cnt != arc.var_cnt) { - int i; + size_t i; - msg (SE, _("Source variable count (%d) does not match " - "target variable count (%d)."), arc.var_cnt, dst_cnt); + msg (SE, _("Source variable count (%u) does not match " + "target variable count (%u)."), + (unsigned) arc.var_cnt, (unsigned) dst_cnt); for (i = 0; i < dst_cnt; i++) free (arc.dst_names[i]); @@ -197,7 +198,7 @@ arc_free (struct autorecode_pgm *arc) free (arc->src_vars); if (arc->dst_names != NULL) { - int i; + size_t i; for (i = 0; i < arc->var_cnt; i++) free (arc->dst_names[i]); @@ -206,7 +207,7 @@ arc_free (struct autorecode_pgm *arc) free (arc->dst_vars); if (arc->src_values != NULL) { - int i; + size_t i; for (i = 0; i < arc->var_cnt; i++) hsh_destroy (arc->src_values[i]); @@ -223,7 +224,7 @@ recode (const struct autorecode_pgm *arc) { struct autorecode_trns *t; struct pool *pool; - int i; + size_t i; pool = pool_create (); t = xmalloc (sizeof *t); @@ -270,7 +271,7 @@ autorecode_trns_proc (struct trns_header * trns, struct ccase * c, int case_idx UNUSED) { struct autorecode_trns *t = (struct autorecode_trns *) trns; - int i; + size_t i; for (i = 0; i < t->spec_cnt; i++) { @@ -293,7 +294,7 @@ static void autorecode_trns_free (struct trns_header * trns) { struct autorecode_trns *t = (struct autorecode_trns *) trns; - int i; + size_t i; for (i = 0; i < t->spec_cnt; i++) hsh_destroy (t->specs[i].items); @@ -342,7 +343,7 @@ static int autorecode_proc_func (struct ccase *c, void *arc_) { struct autorecode_pgm *arc = arc_; - int i; + size_t i; for (i = 0; i < arc->var_cnt; i++) { diff --git a/src/correlations.q b/src/correlations.q index d73c3cff..f190307d 100644 --- a/src/correlations.q +++ b/src/correlations.q @@ -33,7 +33,7 @@ struct cor_set { struct cor_set *next; struct variable **v1, **v2; - int nv1, nv2; + size_t nv1, nv2; }; struct cor_set *cor_list, *cor_last; @@ -84,7 +84,7 @@ static int cor_custom_variables (struct cmd_correlations *cmd UNUSED) { struct variable **v1, **v2; - int nv1, nv2; + size_t nv1, nv2; struct cor_set *cor; /* Ensure that this is a VARIABLES subcommand. */ diff --git a/src/count.c b/src/count.c index 90275084..8988f3cb 100644 --- a/src/count.c +++ b/src/count.c @@ -91,7 +91,7 @@ struct counting /* variables to count */ struct variable **v; - int n; + size_t n; /* values to count */ int missing; /* (numeric only) @@ -232,15 +232,15 @@ fail: static int parse_numeric_criteria (struct counting * c) { - int n = 0; - int m = 0; + size_t n = 0; + size_t m = 0; c->crit.n = 0; c->missing = 0; for (;;) { struct cnt_num *cur; - if (n >= m - 1) + if (n + 1 >= m) { m += 16; c->crit.n = xrealloc (c->crit.n, m * sizeof (struct cnt_num)); @@ -328,10 +328,10 @@ parse_string_criteria (struct counting * c) { int len = 0; - int n = 0; - int m = 0; + size_t n = 0; + size_t m = 0; - int i; + size_t i; for (i = 0; i < c->n; i++) if (c->v[i]->width > len) @@ -341,7 +341,7 @@ parse_string_criteria (struct counting * c) for (;;) { struct cnt_str *cur; - if (n >= m - 1) + if (n + 1 >= m) { m += 16; c->crit.n = xrealloc (c->crit.n, m * sizeof (struct cnt_str)); @@ -371,7 +371,7 @@ static inline int count_numeric (struct counting * cnt, struct ccase * c) { int counter = 0; - int i; + size_t i; for (i = 0; i < cnt->n; i++) { @@ -436,7 +436,7 @@ static inline int count_string (struct counting * cnt, struct ccase * c) { int counter = 0; - int i; + size_t i; for (i = 0; i < cnt->n; i++) { diff --git a/src/crosstabs.q b/src/crosstabs.q index 21d2d3df..aefac603 100644 --- a/src/crosstabs.q +++ b/src/crosstabs.q @@ -302,8 +302,8 @@ crs_custom_tables (struct cmd_crosstabs *cmd UNUSED) struct var_set *var_set; int n_by; struct variable ***by = NULL; - int *by_nvar = NULL; - int nx = 1; + size_t *by_nvar = NULL; + size_t nx = 1; int success = 0; /* Ensure that this is a TABLES subcommand. */ @@ -326,12 +326,17 @@ crs_custom_tables (struct cmd_crosstabs *cmd UNUSED) if (!parse_var_set_vars (var_set, &by[n_by], &by_nvar[n_by], PV_NO_DUPLICATE | PV_NO_SCRATCH)) goto done; + if (xalloc_oversized (nx, by_nvar[n_by])) + { + msg (SE, _("Too many crosstabulation variables or dimensions.")); + goto done; + } nx *= by_nvar[n_by]; n_by++; if (!lex_match (T_BY)) { - if (n_by < 1) + if (n_by < 2) { lex_error (_("expecting BY")); goto done; @@ -345,7 +350,7 @@ crs_custom_tables (struct cmd_crosstabs *cmd UNUSED) int *by_iter = xcalloc (n_by, sizeof *by_iter); int i; - xtab = xrealloc (xtab, sizeof *xtab * (nxtab + nx)); + xtab = xnrealloc (xtab, sizeof *xtab, nxtab + nx); for (i = 0; i < nx; i++) { struct crosstab *x; @@ -408,8 +413,8 @@ crs_custom_variables (struct cmd_crosstabs *cmd UNUSED) for (;;) { - int orig_nv = variables_cnt; - int i; + size_t orig_nv = variables_cnt; + size_t i; long min, max; diff --git a/src/data-list.c b/src/data-list.c index 2b088860..ad8bcc7e 100644 --- a/src/data-list.c +++ b/src/data-list.c @@ -317,7 +317,7 @@ struct fmt_list struct fixed_parsing_state { char **name; /* Variable names. */ - int name_cnt; /* Number of names. */ + size_t name_cnt; /* Number of names. */ int recno; /* Index of current record. */ int sc; /* 1-based column number of starting column for @@ -337,7 +337,7 @@ static int parse_fixed (struct data_list_pgm *dls) { struct fixed_parsing_state fx; - int i; + size_t i; fx.recno = 0; fx.sc = 1; @@ -828,9 +828,9 @@ parse_free (struct dls_var_spec **first, struct dls_var_spec **last) { struct fmt_spec input, output; char **name; - int name_cnt; + size_t name_cnt; int width; - int i; + size_t i; if (!parse_DATA_LIST_vars (&name, &name_cnt, PV_NONE)) return 0; @@ -1722,7 +1722,7 @@ static int parse_repeating_data (struct dls_var_spec **first, struct dls_var_spec **last) { struct fixed_parsing_state fx; - int i; + size_t i; fx.recno = 0; fx.sc = 1; diff --git a/src/descript.c b/src/descript.c index 05e0767d..1e52abf6 100644 --- a/src/descript.c +++ b/src/descript.c @@ -170,7 +170,7 @@ static void free_dsc_proc (struct dsc_proc *); /* Z-score functions. */ static int try_name (struct dsc_proc *dsc, char *name); static int generate_z_varname (struct dsc_proc *dsc, char *z_name, - const char *name, int *z_cnt); + const char *name, size_t *z_cnt); static void dump_z_table (struct dsc_proc *); static void setup_z_trns (struct dsc_proc *); @@ -186,10 +186,10 @@ cmd_descriptives (void) { struct dsc_proc *dsc; struct variable **vars = NULL; - int var_cnt = 0; + size_t var_cnt = 0; int save_z_scores = 0; - int z_cnt = 0; - int i; + size_t z_cnt = 0; + size_t i; /* Create and initialize dsc. */ dsc = xmalloc (sizeof *dsc); @@ -361,7 +361,7 @@ cmd_descriptives (void) { if (save_z_scores) { - int gen_cnt = 0; + size_t gen_cnt = 0; for (i = 0; i < dsc->var_cnt; i++) if (dsc->vars[i].z_name[0] == 0) @@ -464,7 +464,7 @@ free_dsc_proc (struct dsc_proc *dsc) static int try_name (struct dsc_proc *dsc, char *name) { - int i; + size_t i; if (dict_lookup_var (default_dict, name) != NULL) return 0; @@ -480,7 +480,7 @@ try_name (struct dsc_proc *dsc, char *name) copies the new name into Z_NAME. On failure, returns zero. */ static int generate_z_varname (struct dsc_proc *dsc, char *z_name, - const char *var_name, int *z_cnt) + const char *var_name, size_t *z_cnt) { char name[LONG_NAME_LEN + 1]; @@ -527,11 +527,11 @@ generate_z_varname (struct dsc_proc *dsc, char *z_name, static void dump_z_table (struct dsc_proc *dsc) { - int cnt = 0; + size_t cnt = 0; struct tab_table *t; { - int i; + size_t i; for (i = 0; i < dsc->var_cnt; i++) if (dsc->vars[i].z_name[0] != '\0') @@ -549,7 +549,7 @@ dump_z_table (struct dsc_proc *dsc) tab_dim (t, tab_natural_dimensions); { - int i, y; + size_t i, y; for (i = 0, y = 1; i < dsc->var_cnt; i++) if (dsc->vars[i].z_name[0] != '\0') @@ -625,7 +625,7 @@ static void setup_z_trns (struct dsc_proc *dsc) { struct dsc_trns *t; - int cnt, i; + size_t cnt, i; for (cnt = i = 0; i < dsc->var_cnt; i++) if (dsc->vars[i].z_name[0] != '\0') @@ -700,7 +700,7 @@ calc_descriptives (const struct casefile *cf, void *dsc_) struct dsc_proc *dsc = dsc_; struct casereader *reader; struct ccase c; - int i; + size_t i; for (i = 0; i < dsc->var_cnt; i++) { @@ -838,7 +838,7 @@ calc_descriptives (const struct casefile *cf, void *dsc_) static int listwise_missing (struct dsc_proc *dsc, const struct ccase *c) { - int i; + size_t i; for (i = 0; i < dsc->var_cnt; i++) { @@ -861,7 +861,7 @@ static algo_compare_func descriptives_compare_dsc_vars; static void display (struct dsc_proc *dsc) { - int i, j; + size_t i; int nc; struct tab_table *t; @@ -902,6 +902,7 @@ display (struct dsc_proc *dsc) for (i = 0; i < dsc->var_cnt; i++) { struct dsc_var *dv = &dsc->vars[i]; + size_t j; nc = 0; tab_text (t, nc++, i + 1, TAB_LEFT, dv->v->name); diff --git a/src/dictionary.c b/src/dictionary.c index 758f1997..c63b2e1b 100644 --- a/src/dictionary.c +++ b/src/dictionary.c @@ -223,7 +223,7 @@ dict_get_var (const struct dictionary *d, size_t idx) exclude ordinary, system, and/or scratch variables. */ void dict_get_vars (const struct dictionary *d, struct variable ***vars, - int *cnt, unsigned exclude_classes) + size_t *cnt, unsigned exclude_classes) { size_t count; size_t i; diff --git a/src/dictionary.h b/src/dictionary.h index e527dd51..e923d52d 100644 --- a/src/dictionary.h +++ b/src/dictionary.h @@ -34,7 +34,7 @@ void dict_destroy (struct dictionary *); size_t dict_get_var_cnt (const struct dictionary *); struct variable *dict_get_var (const struct dictionary *, size_t idx); void dict_get_vars (const struct dictionary *, - struct variable ***vars, int *cnt, + struct variable ***vars, size_t *cnt, unsigned exclude_classes); struct variable *dict_create_var (struct dictionary *, const char *, diff --git a/src/examine.q b/src/examine.q index 33498d85..7f5396a4 100644 --- a/src/examine.q +++ b/src/examine.q @@ -77,7 +77,7 @@ static struct cmd_examine cmd; static struct variable **dependent_vars; -static int n_dependent_vars; +static size_t n_dependent_vars; struct factor @@ -328,7 +328,7 @@ output_examine(void) if ( cmd.sbc_plot) { - int v; + size_t v; struct factor_statistics **fs = fctr->fs ; @@ -611,7 +611,7 @@ static int bad_weight_warn = 1; void factor_calc(struct ccase *c, int case_no, double weight, int case_missing) { - int v; + size_t v; struct factor *fctr = factors; while ( fctr) @@ -812,7 +812,7 @@ run_examine(const struct casefile *cf, void *cmd_ ) hsh_probe(fctr->fstats, (void *) &key ); if ( !*ffs ) { - int i; + size_t i; (*ffs) = create_factor_statistics (n_dependent_vars, &key[0], &key[1]); for ( i = 0 ; i < n_dependent_vars ; ++i ) @@ -834,7 +834,7 @@ run_examine(const struct casefile *cf, void *cmd_ ) if ( totals ) { - int i; + size_t i; for ( i = 0 ; i < n_dependent_vars ; ++i ) { metrics_destroy(&totals[i]); diff --git a/src/expressions/helpers.c b/src/expressions/helpers.c index 25fe1437..b4534c81 100644 --- a/src/expressions/helpers.c +++ b/src/expressions/helpers.c @@ -158,7 +158,7 @@ alloc_string (struct expression *e, size_t length) } struct fixed_string -copy_string (struct expression *e, const unsigned char *old, size_t length) +copy_string (struct expression *e, const char *old, size_t length) { struct fixed_string s = alloc_string (e, length); memcpy (s.string, old, length); diff --git a/src/expressions/helpers.h b/src/expressions/helpers.h index 0d6082a5..4011d843 100644 --- a/src/expressions/helpers.h +++ b/src/expressions/helpers.h @@ -52,7 +52,7 @@ double expr_yrmoda (double year, double month, double day); struct fixed_string alloc_string (struct expression *, size_t length); struct fixed_string copy_string (struct expression *, - const unsigned char *, size_t length); + const char *, size_t length); static inline bool is_valid (double d) diff --git a/src/expressions/parse.c b/src/expressions/parse.c index bc639cd8..14dedfc9 100644 --- a/src/expressions/parse.c +++ b/src/expressions/parse.c @@ -1158,8 +1158,8 @@ parse_function (struct expression *e) if (token == T_ID && lex_look_ahead () == 'T') { struct variable **vars; - int var_cnt; - int i; + size_t var_cnt; + size_t i; if (!parse_variables (default_dict, &vars, &var_cnt, PV_SINGLE)) goto fail; diff --git a/src/flip.c b/src/flip.c index 7b33d3db..8d703170 100644 --- a/src/flip.c +++ b/src/flip.c @@ -57,7 +57,7 @@ struct flip_pgm { struct variable **var; /* Variables to transpose. */ int *idx_to_fv; /* var[]->index to compacted sink case fv. */ - int var_cnt; /* Number of elements in `var'. */ + size_t var_cnt; /* Number of elements in `var'. */ int case_cnt; /* Pre-flip case count. */ size_t case_size; /* Post-flip bytes per case. */ @@ -124,7 +124,7 @@ cmd_flip (void) if (flip->new_names) { - int i; + size_t i; for (i = 0; i < flip->var_cnt; i++) if (flip->var[i] == flip->new_names) @@ -282,7 +282,7 @@ static struct case_sink * flip_sink_create (struct flip_pgm *flip) { struct flip_sink_info *info = xmalloc (sizeof *info); - int i; + size_t i; info->flip = flip; info->output_buf = xmalloc (sizeof *info->output_buf * flip->var_cnt); @@ -310,7 +310,7 @@ flip_sink_write (struct case_sink *sink, const struct ccase *c) { struct flip_sink_info *info = sink->aux; struct flip_pgm *flip = info->flip; - int i; + size_t i; flip->case_cnt++; @@ -416,7 +416,7 @@ flip_file (struct flip_pgm *flip) { unsigned long read_cases = min (flip->case_cnt - case_idx, case_capacity); - int i; + size_t i; if (read_cases != fread (input_buf, case_bytes, read_cases, input_file)) msg (FE, _("Error reading FLIP file: %s."), strerror (errno)); @@ -497,7 +497,7 @@ flip_source_read (struct case_source *source, { struct flip_pgm *flip = source->aux; union value *input_buf; - int i; + size_t i; input_buf = xmalloc (sizeof *input_buf * flip->case_cnt); for (i = 0; i < flip->var_cnt; i++) diff --git a/src/formats.c b/src/formats.c index a569c678..32d638ae 100644 --- a/src/formats.c +++ b/src/formats.c @@ -64,7 +64,7 @@ internal_cmd_formats (int which) { /* Variables. */ struct variable **v; - int cv; + size_t cv; /* Format to set the variables to. */ struct fmt_spec f; @@ -73,7 +73,7 @@ internal_cmd_formats (int which) int type; /* Counter. */ - int i; + size_t i; for (;;) { diff --git a/src/frequencies.q b/src/frequencies.q index 0ca83a45..460efea6 100644 --- a/src/frequencies.q +++ b/src/frequencies.q @@ -188,7 +188,7 @@ static double scale, incr; /* FIXME */ static int normal; /* FIXME */ /* Variables for which to calculate statistics. */ -static int n_variables; +static size_t n_variables; static struct variable **v_variables; /* Arenas used to store semi-permanent storage. */ @@ -493,7 +493,7 @@ static int calc (struct ccase *c, void *aux UNUSED) { double weight; - int i; + size_t i; int bad_warn = 1; weight = dict_get_case_weight (default_dict, c, &bad_warn); @@ -547,7 +547,7 @@ calc (struct ccase *c, void *aux UNUSED) static void precalc (void *aux UNUSED) { - int i; + size_t i; pool_destroy (gen_pool); gen_pool = pool_create (); @@ -591,7 +591,7 @@ precalc (void *aux UNUSED) static void postcalc (void *aux UNUSED) { - int i; + size_t i; for (i = 0; i < n_variables; i++) { @@ -773,8 +773,8 @@ frq_custom_variables (struct cmd_frequencies *cmd UNUSED) int mode; int min = 0, max = 0; - int old_n_variables = n_variables; - int i; + size_t old_n_variables = n_variables; + size_t i; lex_match ('='); if (token != T_ALL && (token != T_ID @@ -856,14 +856,14 @@ frq_custom_grouped (struct cmd_frequencies *cmd UNUSED) || token == T_ID) for (;;) { - int i; + size_t i; /* Max, current size of list; list itself. */ int nl, ml; double *dl; /* Variable list. */ - int n; + size_t n; struct variable **v; if (!parse_variables (default_dict, &v, &n, diff --git a/src/get.c b/src/get.c index debc85b7..a00663a5 100644 --- a/src/get.c +++ b/src/get.c @@ -559,13 +559,13 @@ parse_dict_trim (struct dictionary *dict) static bool rename_variables (struct dictionary *dict) { - int i; + size_t i; int success = 0; struct variable **v; char **new_names; - int nv, nn; + size_t nv, nn; char *err_name; int group; @@ -602,7 +602,7 @@ rename_variables (struct dictionary *dict) group = 1; while (lex_match ('(')) { - int old_nv = nv; + size_t old_nv = nv; if (!parse_variables (dict, &v, &nv, PV_NO_DUPLICATE | PV_APPEND)) goto done; @@ -618,7 +618,7 @@ rename_variables (struct dictionary *dict) msg (SE, _("Number of variables on left side of `=' (%d) does not " "match number of variables on right side (%d), in " "parenthesized group %d of RENAME subcommand."), - nv - old_nv, nn - old_nv, group); + (unsigned) (nv - old_nv), (unsigned) (nn - old_nv), group); goto done; } if (!lex_force_match (')')) @@ -648,7 +648,7 @@ static bool drop_variables (struct dictionary *dict) { struct variable **v; - int nv; + size_t nv; lex_match ('='); if (!parse_variables (dict, &v, &nv, PV_NONE)) @@ -670,8 +670,8 @@ static bool keep_variables (struct dictionary *dict) { struct variable **v; - int nv; - int i; + size_t nv; + size_t i; lex_match ('='); if (!parse_variables (dict, &v, &nv, PV_NONE)) @@ -726,7 +726,7 @@ struct mtf_proc struct mtf_file *head; /* First file mentioned on FILE or TABLE. */ struct mtf_file *tail; /* Last file mentioned on FILE or TABLE. */ - int by_cnt; /* Number of variables on BY subcommand. */ + size_t by_cnt; /* Number of variables on BY subcommand. */ /* Names of FIRST, LAST variables. */ char first[LONG_NAME_LEN + 1], last[LONG_NAME_LEN + 1]; @@ -919,7 +919,7 @@ cmd_match_files (void) for (iter = mtf.head; iter != NULL; iter = iter->next) { - int i; + size_t i; iter->by = xmalloc (sizeof *iter->by * mtf.by_cnt); diff --git a/src/html.c b/src/html.c index f902520d..1b56ba1c 100644 --- a/src/html.c +++ b/src/html.c @@ -250,7 +250,7 @@ postopen (struct file_ext *f) FILE *prologue_file; char *buf = NULL; - int buf_size = 0; + size_t buf_size = 0; if (prologue_fn == NULL) { diff --git a/src/levene.c b/src/levene.c index 7877c7ec..04f5a1de 100644 --- a/src/levene.c +++ b/src/levene.c @@ -68,7 +68,7 @@ struct levene_info struct variable *v_indep; /* Number of dependent variables */ - int n_dep; + size_t n_dep; /* The dependent variables */ struct variable **v_dep; @@ -94,7 +94,7 @@ static void levene2_postcalc (void *); void levene(const struct casefile *cf, - struct variable *v_indep, int n_dep, struct variable **v_dep, + struct variable *v_indep, size_t n_dep, struct variable **v_dep, enum lev_missing missing, is_missing_func value_is_missing) { struct casereader *r; @@ -156,7 +156,7 @@ static struct lz_stats *lz; static void levene_precalc (const struct levene_info *l) { - int i; + size_t i; lz = xmalloc (sizeof (struct lz_stats ) * l->n_dep ) ; @@ -186,7 +186,7 @@ levene_precalc (const struct levene_info *l) static int levene_calc (const struct ccase *c, void *_l) { - int i; + size_t i; int warn = 0; struct levene_info *l = (struct levene_info *) _l; const union value *gv = case_data (c, l->v_indep->fv); @@ -241,7 +241,7 @@ levene_calc (const struct ccase *c, void *_l) static void levene_postcalc (void *_l) { - int v; + size_t v; struct levene_info *l = (struct levene_info *) _l; @@ -261,7 +261,7 @@ static double *lz_denominator; static void levene2_precalc (void *_l) { - int v; + size_t v; struct levene_info *l = (struct levene_info *) _l; @@ -290,7 +290,7 @@ levene2_precalc (void *_l) static int levene2_calc (const struct ccase *c, void *_l) { - int i; + size_t i; int warn = 0; struct levene_info *l = (struct levene_info *) _l; @@ -343,7 +343,7 @@ levene2_calc (const struct ccase *c, void *_l) static void levene2_postcalc (void *_l) { - int v; + size_t v; struct levene_info *l = (struct levene_info *) _l; diff --git a/src/levene.h b/src/levene.h index 1889a18a..fd2aaf54 100644 --- a/src/levene.h +++ b/src/levene.h @@ -41,7 +41,7 @@ The dependent variables : v_dep; void levene(const struct casefile *cf, - struct variable *v_indep, int n_dep, struct variable **v_dep, + struct variable *v_indep, size_t n_dep, struct variable **v_dep, enum lev_missing, is_missing_func); diff --git a/src/list.q b/src/list.q index 1876f69f..d55e76cc 100644 --- a/src/list.q +++ b/src/list.q @@ -32,6 +32,7 @@ #include "misc.h" #include "htmlP.h" #include "output.h" +#include "size_max.h" #include "som.h" #include "tab.h" #include "var.h" @@ -60,8 +61,8 @@ struct list_ext { int type; /* 0=Values and labels fit across the page. */ - int n_vertical; /* Number of labels to list vertically. */ - int header_rows; /* Number of header rows. */ + size_t n_vertical; /* Number of labels to list vertically. */ + size_t header_rows; /* Number of header rows. */ char **header; /* The header itself. */ }; @@ -75,8 +76,8 @@ static int case_idx; static char *line_buf; /* TTY-style output functions. */ -static int n_lines_remaining (struct outp_driver *d); -static int n_chars_width (struct outp_driver *d); +static unsigned n_lines_remaining (struct outp_driver *d); +static unsigned n_chars_width (struct outp_driver *d); static void write_line (struct outp_driver *d, char *s); /* Other functions. */ @@ -88,7 +89,7 @@ static void write_all_headers (void *); /* Returns the number of text lines that can fit on the remainder of the page. */ -static inline int +static inline unsigned n_lines_remaining (struct outp_driver *d) { int diff; @@ -99,7 +100,7 @@ n_lines_remaining (struct outp_driver *d) /* Returns the number of fixed-width character that can fit across the page. */ -static inline int +static inline unsigned n_chars_width (struct outp_driver *d) { return d->width / d->fixed_width; @@ -181,7 +182,7 @@ cmd_list (void) { if (dict_get_weight (default_dict) != NULL) { - int i; + size_t i; for (i = 0; i < cmd.n_variables; i++) if (cmd.v_variables[i] == dict_get_weight (default_dict)) @@ -261,7 +262,7 @@ write_all_headers (void *aux UNUSED) fputs ("\n \n", x->file.file); { - int i; + size_t i; for (i = 0; i < cmd.n_variables; i++) fprintf (x->file.file, " \n", @@ -298,8 +299,9 @@ write_header (struct outp_driver *d) /* Design the header. */ if (!prc->header) { - int i, x; - + size_t i; + size_t x; + /* Allocate, initialize header. */ prc->header = xmalloc (sizeof (char *) * prc->header_rows); { @@ -315,11 +317,11 @@ write_header (struct outp_driver *d) for (i = x = 0; i < prc->n_vertical; i++) { struct variable *v = cmd.v_variables[i]; - int j; + size_t j; memset (&prc->header[prc->header_rows - 1][x], '-', v->print.w); x += v->print.w - 1; - for (j = 0; j < (int) strlen (v->name); j++) + for (j = 0; j < strlen (v->name); j++) prc->header[strlen (v->name) - j - 1][x] = v->name[j]; x += 2; } @@ -351,13 +353,14 @@ write_header (struct outp_driver *d) } /* Write out the header, in back-to-front order except for the last line. */ - { - int i; - - for (i = prc->header_rows - 2; i >= 0; i--) - write_line (d, prc->header[i]); - write_line (d, prc->header[prc->header_rows - 1]); - } + if (prc->header_rows >= 2) + { + size_t i; + + for (i = prc->header_rows - 1; i-- != 0; ) + write_line (d, prc->header[i]); + } + write_line (d, prc->header[prc->header_rows - 1]); } @@ -371,7 +374,7 @@ clean_up (void) if (d->class->special == 0) { struct list_ext *prc = d->prc; - int i; + size_t i; if (prc->header) { @@ -519,7 +522,7 @@ determine_layout (void) for (d = outp_drivers (NULL); d; d = outp_drivers (d)) { - int column; /* Current column. */ + size_t column; /* Current column. */ int width; /* Accumulated width. */ int height; /* Height of vertical names. */ int max_width; /* Page width. */ @@ -577,9 +580,9 @@ determine_layout (void) if (width <= max_width && height <= SHORT_NAME_LEN) { #ifndef NDEBUG - prc->n_vertical = -1; + prc->n_vertical = SIZE_MAX; #endif - for (column = cmd.n_variables - 1; column >= 0; column--) + for (column = cmd.n_variables; column-- != 0; ) { struct variable *v = cmd.v_variables[column]; int trial_width = (width - v->print.w @@ -592,7 +595,7 @@ determine_layout (void) } width = trial_width; } - assert(prc->n_vertical != -1); + assert (prc->n_vertical != SIZE_MAX); prc->n_vertical = cmd.n_variables; /* Finally determine the length of the headers. */ @@ -600,7 +603,7 @@ determine_layout (void) column < prc->n_vertical; column++) prc->header_rows = max (prc->header_rows, - (int) strlen (cmd.v_variables[column]->name)); + strlen (cmd.v_variables[column]->name)); prc->header_rows++; d->class->text_set_font_by_name (d, "FIXED"); diff --git a/src/matrix-data.c b/src/matrix-data.c index e0dfdcee..03b06ebc 100644 --- a/src/matrix-data.c +++ b/src/matrix-data.c @@ -132,7 +132,7 @@ struct matrix_data_pgm struct variable *single_split; /* Single SPLIT FILE variable. */ /* Factor variables. */ - int n_factors; /* Number of factor variables. */ + size_t n_factors; /* Number of factor variables. */ struct variable **factors; /* Factor variables. */ int is_per_factor[PROX + 1]; /* Is there per-factor data? */ @@ -204,7 +204,7 @@ cmd_matrix_data (void) if (lex_match_id ("VARIABLES")) { char **v; - int nv; + size_t nv; if (seen & 1) { @@ -218,7 +218,7 @@ cmd_matrix_data (void) goto lossage; { - int i; + size_t i; for (i = 0; i < nv; i++) if (!strcasecmp (v[i], "VARNAME_")) @@ -233,7 +233,7 @@ cmd_matrix_data (void) } { - int i; + size_t i; for (i = 0; i < nv; i++) { @@ -327,7 +327,7 @@ cmd_matrix_data (void) else { struct variable **split; - int n; + size_t n; if (!parse_variables (default_dict, &split, &n, PV_NO_DUPLICATE)) goto lossage; @@ -366,11 +366,12 @@ cmd_matrix_data (void) } seen |= 4; - if (!parse_variables (default_dict, &mx->factors, &mx->n_factors, PV_NONE)) + if (!parse_variables (default_dict, &mx->factors, &mx->n_factors, + PV_NONE)) goto lossage; { - int i; + size_t i; for (i = 0; i < mx->n_factors; i++) { @@ -571,7 +572,7 @@ cmd_matrix_data (void) system file output. */ { struct variable **v; - int nv; + size_t nv; dict_get_vars (default_dict, &v, &nv, 0); qsort (v, nv, sizeof *v, compare_variables_by_mxd_var_type); @@ -960,7 +961,8 @@ read_matrices_without_rowtype (struct matrix_data_pgm *mx) nr.mx = mx; nr.data = NULL; - nr.factor_values = xmalloc (sizeof *nr.factor_values * mx->n_factors * mx->cells); + nr.factor_values = xmalloc (sizeof *nr.factor_values + * mx->n_factors * mx->cells); nr.max_cell_idx = 0; nr.split_values = xmalloc (sizeof *nr.split_values * dict_get_split_cnt (default_dict)); @@ -1309,7 +1311,7 @@ nr_read_factors (struct nr_aux_data *nr, int cell) } { - int i; + size_t i; for (i = 0; i < mx->n_factors; i++) { @@ -1403,7 +1405,7 @@ nr_output_data (struct nr_aux_data *nr, struct ccase *c, for (cell = 0; cell < mx->cells; cell++) { { - int factor; + size_t factor; for (factor = 0; factor < mx->n_factors; factor++) { @@ -1433,7 +1435,7 @@ nr_output_data (struct nr_aux_data *nr, struct ccase *c, int content; { - int factor; + size_t factor; for (factor = 0; factor < mx->n_factors; factor++) case_data_rw (c, mx->factors[factor]->fv)->f = SYSMIS; @@ -1664,7 +1666,7 @@ wr_output_data (struct wr_aux_data *wr, for (iter = wr->data; iter; iter = iter->next) { { - int factor; + size_t factor; for (factor = 0; factor < mx->n_factors; factor++) case_data_rw (c, mx->factors[factor]->fv)->f @@ -1765,7 +1767,7 @@ wr_read_factors (struct wr_aux_data *wr) wr->content = -1; { - int i; + size_t i; for (i = 0; i < mx->n_factors; i++) { @@ -1802,7 +1804,7 @@ wr_read_factors (struct wr_aux_data *wr) mechanism. */ if (wr->current) { - int i; + size_t i; for (i = 0; i < mx->n_factors; i++) if (factor_values[i] != wr->current->factors[i]) @@ -1817,7 +1819,7 @@ cache_miss: for (iter = wr->data; iter; iter = iter->next) { - int i; + size_t i; for (i = 0; i < mx->n_factors; i++) if (factor_values[i] != iter->factors[i]) @@ -1834,10 +1836,11 @@ cache_miss: { struct factor_data *new = pool_alloc (mx->container, sizeof *new); - new->factors = pool_alloc (mx->container, sizeof *new->factors * mx->n_factors); + new->factors = pool_alloc (mx->container, + sizeof *new->factors * mx->n_factors); { - int i; + size_t i; for (i = 0; i < mx->n_factors; i++) new->factors[i] = factor_values[i]; diff --git a/src/means.q b/src/means.q index f367d42c..baad486b 100644 --- a/src/means.q +++ b/src/means.q @@ -53,7 +53,7 @@ /* TABLES: Variable lists for each dimension. */ int n_dim; /* Number of dimensions. */ -int *nv_dim; /* Number of variables in each dimension. */ +size_t *nv_dim; /* Number of variables in each dimension. */ struct variable ***v_dim; /* Variables in each dimension. */ /* VARIABLES: List of variables. */ @@ -145,7 +145,7 @@ mns_custom_tables (struct cmd_means *cmd) do { - int nvl; + size_t nvl; struct variable **vl; if (!parse_var_set_vars (var_set, &vl, &nvl, diff --git a/src/mis-val.c b/src/mis-val.c index 555dbf09..3db00110 100644 --- a/src/mis-val.c +++ b/src/mis-val.c @@ -39,15 +39,14 @@ int cmd_missing_values (void) { struct variable **v; - int nv; + size_t nv; int retval = CMD_PART_SUCCESS_MAYBE; bool deferred_errors = false; while (token != '.') { - int i; - + size_t i; if (!parse_variables (default_dict, &v, &nv, PV_NONE)) goto done; diff --git a/src/modify-vars.c b/src/modify-vars.c index 20898e0a..5f1ad4c9 100644 --- a/src/modify-vars.c +++ b/src/modify-vars.c @@ -109,7 +109,7 @@ cmd_modify_vars (void) if (lex_match_id ("REORDER")) { struct variable **v = NULL; - int nv = 0; + size_t nv = 0; if (already_encountered & 1) { @@ -122,7 +122,7 @@ cmd_modify_vars (void) do { struct ordering ordering; - int prev_nv = nv; + size_t prev_nv = nv; ordering.forward = ordering.positional = 1; if (lex_match_id ("FORWARD")); @@ -184,8 +184,8 @@ cmd_modify_vars (void) lex_match ('='); do { - int prev_nv_1 = vm.rename_cnt; - int prev_nv_2 = vm.rename_cnt; + size_t prev_nv_1 = vm.rename_cnt; + size_t prev_nv_2 = vm.rename_cnt; if (!lex_match ('(')) { @@ -226,7 +226,7 @@ cmd_modify_vars (void) else if (lex_match_id ("KEEP")) { struct variable **keep_vars, **all_vars, **drop_vars; - int keep_cnt, all_cnt, drop_cnt; + size_t keep_cnt, all_cnt, drop_cnt; if (already_encountered & 4) { @@ -247,6 +247,7 @@ cmd_modify_vars (void) compare_variables_given_ordering, &forward_positional_ordering); dict_get_vars (default_dict, &all_vars, &all_cnt, 0); + assert (all_cnt >= keep_cnt); drop_cnt = all_cnt - keep_cnt; drop_vars = xmalloc (drop_cnt * sizeof *keep_vars); @@ -268,7 +269,7 @@ cmd_modify_vars (void) else if (lex_match_id ("DROP")) { struct variable **drop_vars; - int drop_cnt; + size_t drop_cnt; if (already_encountered & 4) { @@ -391,7 +392,7 @@ validate_var_modification (const struct dictionary *d, struct variable **keep_vars; struct variable **drop_vars; size_t keep_cnt, drop_cnt; - int all_cnt; + size_t all_cnt; struct var_renaming *var_renaming; int valid; @@ -408,6 +409,7 @@ validate_var_modification (const struct dictionary *d, compare_variables_given_ordering, &forward_positional_ordering); /* Keep variables, in index order. */ + assert (all_cnt >= drop_cnt); keep_cnt = all_cnt - drop_cnt; keep_vars = xmalloc (keep_cnt * sizeof *keep_vars); if (set_difference (all_vars, all_cnt, diff --git a/src/numeric.c b/src/numeric.c index a2b6d804..2a7dbe57 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -36,11 +36,11 @@ int cmd_numeric (void) { - int i; + size_t i; /* Names of variables to create. */ char **v; - int nv; + size_t nv; /* Format spec for variables to create. f.type==-1 if default is to be used. */ @@ -107,11 +107,11 @@ fail: int cmd_string (void) { - int i; + size_t i; /* Names of variables to create. */ char **v; - int nv; + size_t nv; /* Format spec for variables to create. */ struct fmt_spec f; @@ -187,9 +187,9 @@ int cmd_leave (void) { struct variable **v; - int nv; + size_t nv; - int i; + size_t i; if (!parse_variables (default_dict, &v, &nv, PV_NONE)) return CMD_FAILURE; diff --git a/src/oneway.q b/src/oneway.q index 8c9c768a..26f2f0ce 100644 --- a/src/oneway.q +++ b/src/oneway.q @@ -71,7 +71,7 @@ static struct cmd_oneway cmd; static struct variable *indep_var; /* Number of dependent variables */ -static int n_vars; +static size_t n_vars; /* The dependent variables */ static struct variable **vars; @@ -154,8 +154,7 @@ cmd_oneway(void) void output_oneway(void) { - - int i; + size_t i; short *bad_contrast ; bad_contrast = xmalloc ( sizeof (short) * cmd.sbc_contrast ); @@ -258,9 +257,9 @@ oneway_custom_variables(struct cmd_oneway *cmd UNUSED) static void show_anova_table(void) { - int i; + size_t i; int n_cols =7; - int n_rows = n_vars * 3 + 1; + size_t n_rows = n_vars * 3 + 1; struct tab_table *t; @@ -364,7 +363,7 @@ show_anova_table(void) static void show_descriptives(void) { - int v; + size_t v; int n_cols =10; struct tab_table *t; int row; @@ -511,9 +510,9 @@ show_descriptives(void) static void show_homogeneity(void) { - int v; + size_t v; int n_cols = 5; - int n_rows = n_vars + 1; + size_t n_rows = n_vars + 1; struct tab_table *t; @@ -650,9 +649,9 @@ show_contrast_coeffs(short *bad_contrast) static void show_contrast_tests(short *bad_contrast) { - int v; + size_t v; int n_cols = 8; - int n_rows = 1 + n_vars * 2 * cmd.sbc_contrast; + size_t n_rows = 1 + n_vars * 2 * cmd.sbc_contrast; struct tab_table *t; @@ -857,7 +856,7 @@ static void precalc ( struct cmd_oneway *cmd UNUSED ); static void precalc ( struct cmd_oneway *cmd UNUSED ) { - int i=0; + size_t i=0; for(i=0; i< n_vars ; ++i) { @@ -905,7 +904,7 @@ run_oneway(const struct casefile *cf, void *cmd_) casereader_read (r, &c) ; case_destroy (&c)) { - int i; + size_t i; const double weight = dict_get_case_weight(default_dict,&c,&bad_weight_warn); @@ -1016,7 +1015,7 @@ run_oneway(const struct casefile *cf, void *cmd_) void postcalc ( struct cmd_oneway *cmd UNUSED ) { - int i=0; + size_t i=0; for(i = 0; i < n_vars ; ++i) diff --git a/src/print.c b/src/print.c index ccbb8c8c..a42c82d5 100644 --- a/src/print.c +++ b/src/print.c @@ -249,8 +249,8 @@ struct fmt_list static struct { struct variable **v; /* variable list */ - int nv; /* number of variables in list */ - int cv; /* number of variables from list used up so far + size_t nv; /* number of variables in list */ + size_t cv; /* number of variables from list used up so far by the FORTRAN-like format specifiers */ int recno; /* current 1-based record number */ @@ -452,7 +452,7 @@ parse_variable_argument (void) else { /* User wants dictionary format specifiers. */ - int i; + size_t i; lex_match ('*'); for (i = 0; i < fx.nv; i++) @@ -500,9 +500,9 @@ check_string_width (const struct fmt_spec *format, const struct variable *v) static int fixed_parse_compatible (void) { - int dividend; + int individual_var_width; int type; - int i; + size_t i; type = fx.v[0]->type; for (i = 1; i < fx.nv; i++) @@ -610,13 +610,14 @@ fixed_parse_compatible (void) if ((fx.lc - fx.fc + 1) % fx.nv) { - msg (SE, _("The %d columns %d-%d can't be evenly divided into %d " - "fields."), fx.lc - fx.fc + 1, fx.fc + 1, fx.lc + 1, fx.nv); + msg (SE, _("The %d columns %d-%d can't be evenly divided into %u " + "fields."), + fx.lc - fx.fc + 1, fx.fc + 1, fx.lc + 1, (unsigned) fx.nv); return 0; } - dividend = (fx.lc - fx.fc + 1) / fx.nv; - fx.spec.u.v.f.w = dividend; + individual_var_width = (fx.lc - fx.fc + 1) / fx.nv; + fx.spec.u.v.f.w = individual_var_width; if (!check_output_specifier (&fx.spec.u.v.f, true) || !check_specifier_type (&fx.spec.u.v.f, type, true)) return 0; @@ -630,7 +631,7 @@ fixed_parse_compatible (void) fx.spec.type = PRT_VAR; for (i = 0; i < fx.nv; i++) { - fx.spec.fc = fx.fc + dividend * i; + fx.spec.fc = fx.fc + individual_var_width * i; fx.spec.u.v.v = fx.v[i]; append_var_spec (&fx.spec); } diff --git a/src/q2c.c b/src/q2c.c index 545f26fe..bc7af967 100644 --- a/src/q2c.c +++ b/src/q2c.c @@ -1143,7 +1143,7 @@ dump_declarations (void) break; case SBC_VARLIST: - dump (0, "int %sn_%s;", st_lower (sbc->prefix), + dump (0, "size_t %sn_%s;", st_lower (sbc->prefix), st_lower (sbc->name)); dump (0, "struct variable **%sv_%s;", st_lower (sbc->prefix), st_lower (sbc->name)); diff --git a/src/rank.q b/src/rank.q index ddaa020c..56493cfe 100644 --- a/src/rank.q +++ b/src/rank.q @@ -71,12 +71,12 @@ struct rank_spec static struct rank_spec *rank_specs; -static int n_rank_specs; +static size_t n_rank_specs; static struct sort_criteria *sc; static struct variable **group_vars; -static int n_group_vars; +static size_t n_group_vars; static struct cmd_rank cmd; @@ -87,7 +87,7 @@ int cmd_rank(void); int cmd_rank(void) { - int i; + size_t i; n_rank_specs = 0; if ( !parse_rank(&cmd) ) diff --git a/src/recode.c b/src/recode.c index 9f7214bd..a4349826 100644 --- a/src/recode.c +++ b/src/recode.c @@ -75,7 +75,7 @@ struct rcd_var union value sysmis; /* Coding for SYSMIS (if src is numeric). */ struct coding *map; /* Coding for other values. */ - int nmap, mmap; /* Length of map, max capacity of map. */ + size_t nmap, mmap; /* Length of map, max capacity of map. */ }; /* RECODE transformation. */ @@ -118,7 +118,7 @@ static double convert_to_double (const char *, int); int cmd_recode (void) { - int i; + size_t i; /* Transformation that we're constructing. */ struct rcd_var *rcd; @@ -145,7 +145,7 @@ cmd_recode (void) /* Variables in the current part of the recoding. */ struct variable **v; - int nv; + size_t nv; /* Parses each specification between slashes. */ head = rcd = xmalloc (sizeof *rcd); @@ -190,7 +190,7 @@ cmd_recode (void) for (;;) { /* Get the input value (before the `='). */ - int mark = rcd->nmap; + size_t mark = rcd->nmap; int code = parse_src_spec (rcd, type, max_src_width); if (!code) goto lossage; @@ -271,7 +271,7 @@ cmd_recode (void) if (lex_match_id ("INTO")) { char **names; - int nnames; + size_t nnames; int success = 0; @@ -283,10 +283,10 @@ cmd_recode (void) for (i = 0; i < nnames; i++) free (names[i]); free (names); - msg (SE, _("%d variable(s) cannot be recoded into " - "%d variable(s). Specify the same number " + msg (SE, _("%u variable(s) cannot be recoded into " + "%u variable(s). Specify the same number " "of variables as input and output variables."), - nv, nnames); + (unsigned) nv, (unsigned) nnames); goto lossage; } @@ -298,18 +298,20 @@ cmd_recode (void) if (!v) { msg (SE, _("There is no string variable named " - "%s. (All string variables specified " - "on INTO must already exist. Use the " - "STRING command to create a string " - "variable.)"), names[i]); + "%s. (All string variables specified " + "on INTO must already exist. Use the " + "STRING command to create a string " + "variable.)"), + names[i]); goto INTO_fail; } if (v->type != ALPHA) { msg (SE, _("Type mismatch between input and output " - "variables. Output variable %s is not " - "a string variable, but all the input " - "variables are string variables."), v->name); + "variables. Output variable %s is not " + "a string variable, but all the input " + "variables are string variables."), + v->name); goto INTO_fail; } if (v->width > (int) max_dst_width) @@ -519,7 +521,7 @@ parse_src_spec (struct rcd_var * rcd, int type, size_t max_src_width) for (;;) { - if (rcd->nmap >= rcd->mmap - 1) + if (rcd->nmap + 1 >= rcd->mmap) { rcd->mmap += 16; rcd->map = xrealloc (rcd->map, rcd->mmap * sizeof *rcd->map); @@ -649,7 +651,7 @@ parse_src_spec (struct rcd_var * rcd, int type, size_t max_src_width) static void recode_trns_free (struct trns_header * t) { - int i; + size_t i; struct rcd_var *head, *next; head = ((struct recode_trns *) t)->codings; @@ -834,11 +836,11 @@ static long int string_to_long (const char *nptr, int width, const char **endptr) { int negative; - register unsigned long int cutoff; - register unsigned int cutlim; - register unsigned long int i; - register const char *s; - register unsigned char c; + unsigned long int cutoff; + unsigned int cutlim; + unsigned long int i; + const char *s; + unsigned char c; const char *save; s = nptr; @@ -909,7 +911,7 @@ string_to_long (const char *nptr, int width, const char **endptr) static double convert_to_double (const char *s, int width) { - register const char *end = &s[width]; + const char *end = &s[width]; short int sign; diff --git a/src/regression.q b/src/regression.q index 2e54e46c..e3017da5 100644 --- a/src/regression.q +++ b/src/regression.q @@ -94,7 +94,7 @@ static void statistics_keyword_output (void (*)(pspp_linreg_cache *), static void reg_stats_r (pspp_linreg_cache * c) { - struct table *t; + struct tab_table *t; int n_rows = 2; int n_cols = 5; double rsq; @@ -447,7 +447,7 @@ is_depvar (size_t k) } static void -run_regression (const struct casefile *cf, void *cmd_) +run_regression (const struct casefile *cf, void *cmd_ UNUSED) { size_t i; size_t k; diff --git a/src/rename-vars.c b/src/rename-vars.c index 57af1c01..86250909 100644 --- a/src/rename-vars.c +++ b/src/rename-vars.c @@ -39,13 +39,11 @@ cmd_rename_variables (void) { struct variable **rename_vars = NULL; char **rename_new_names = NULL; - int rename_cnt = 0; + size_t rename_cnt = 0; char *err_name; int status = CMD_FAILURE; - int i; - if (temporary != 0) { msg (SE, _("RENAME VARS may not be used after TEMPORARY. " @@ -55,8 +53,8 @@ cmd_rename_variables (void) do { - int prev_nv_1 = rename_cnt; - int prev_nv_2 = rename_cnt; + size_t prev_nv_1 = rename_cnt; + size_t prev_nv_2 = rename_cnt; if (!lex_match ('(')) { @@ -75,9 +73,12 @@ cmd_rename_variables (void) goto lossage; if (prev_nv_1 != rename_cnt) { + size_t i; + msg (SE, _("Differing number of variables in old name list " - "(%d) and in new name list (%d)."), - rename_cnt - prev_nv_2, prev_nv_1 - prev_nv_2); + "(%u) and in new name list (%u)."), + (unsigned) rename_cnt - prev_nv_2, + (unsigned) prev_nv_1 - prev_nv_2); for (i = 0; i < prev_nv_1; i++) free (rename_new_names[i]); free (rename_new_names); @@ -106,6 +107,7 @@ cmd_rename_variables (void) free (rename_vars); if (rename_new_names != NULL) { + size_t i; for (i = 0; i < rename_cnt; i++) free (rename_new_names[i]); free (rename_new_names); diff --git a/src/repeat.c b/src/repeat.c index 0f5bb42f..a5d2dfb8 100644 --- a/src/repeat.c +++ b/src/repeat.c @@ -341,8 +341,8 @@ internal_cmd_do_repeat (void) static int parse_ids (struct repeat_entry * e) { - int i; - int n = 0; + size_t i; + size_t n = 0; e->type = 1; e->replacement = NULL; @@ -350,7 +350,7 @@ parse_ids (struct repeat_entry * e) do { char **names; - int nnames; + size_t nnames; if (!parse_mixed_vars (&names, &nnames, PV_NONE)) return 0; diff --git a/src/sort-prs.c b/src/sort-prs.c index 2114d093..3966eac1 100644 --- a/src/sort-prs.c +++ b/src/sort-prs.c @@ -47,7 +47,7 @@ static bool is_terminator(int tok, const int *terminators); */ struct sort_criteria * sort_parse_criteria (const struct dictionary *dict, - struct variable ***vars, int *var_cnt, + struct variable ***vars, size_t *var_cnt, bool *saw_direction, const int *terminators ) @@ -74,7 +74,7 @@ sort_parse_criteria (const struct dictionary *dict, do { - int prev_var_cnt = *var_cnt; + size_t prev_var_cnt = *var_cnt; enum sort_direction direction; /* Variables. */ diff --git a/src/sort-prs.h b/src/sort-prs.h index b2c1e54f..f2caf723 100644 --- a/src/sort-prs.h +++ b/src/sort-prs.h @@ -27,7 +27,7 @@ struct variable; struct dictionary; struct sort_criteria *sort_parse_criteria (const struct dictionary *, - struct variable ***, int *, + struct variable ***, size_t *, bool *saw_direction, const int *terminators ); diff --git a/src/split-file.c b/src/split-file.c index 506a433c..c9e144f9 100644 --- a/src/split-file.c +++ b/src/split-file.c @@ -35,7 +35,7 @@ cmd_split_file (void) else { struct variable **v; - int n; + size_t n; /* For now, ignore SEPARATE and LAYERED. */ lex_match_id ("SEPARATE") || lex_match_id ("LAYERED"); diff --git a/src/sysfile-info.c b/src/sysfile-info.c index 45bffad7..85344847 100644 --- a/src/sysfile-info.c +++ b/src/sysfile-info.c @@ -171,7 +171,7 @@ cmd_sysfile_info (void) static void display_macros (void); static void display_documents (void); -static void display_variables (struct variable **, int, int); +static void display_variables (struct variable **, size_t, int); static void display_vectors (int sorted); int @@ -181,7 +181,7 @@ cmd_display (void) int sorted; /* Variables to display. */ - int n; + size_t n; struct variable **vl; if (lex_match_id ("MACROS")) @@ -247,7 +247,7 @@ cmd_display (void) if (as == AS_SCRATCH) { - int i, m; + size_t i, m; for (i = 0, m = n; i < n; i++) if (dict_class_from_id (vl[i]->name) != DC_SCRATCH) { @@ -341,7 +341,7 @@ variables_dim (struct tab_table *t, struct outp_driver *d) } static void -display_variables (struct variable **vl, int n, int as) +display_variables (struct variable **vl, size_t n, int as) { struct variable **vp = vl; /* Variable pointer. */ struct tab_table *t; @@ -349,7 +349,7 @@ display_variables (struct variable **vl, int n, int as) int nr; /* Number of rows. */ int pc; /* `Position column' */ int r; /* Current row. */ - int i; + size_t i; _as = as; switch (as) diff --git a/src/t-test.q b/src/t-test.q index 89f1741f..5334a27a 100644 --- a/src/t-test.q +++ b/src/t-test.q @@ -26,23 +26,24 @@ #include #include #include "alloc.h" -#include "str.h" #include "case.h" +#include "casefile.h" #include "command.h" #include "dictionary.h" -#include "lexer.h" #include "error.h" +#include "group_proc.h" +#include "hash.h" +#include "levene.h" +#include "lexer.h" #include "magic.h" #include "misc.h" -#include "tab.h" +#include "size_max.h" #include "som.h" +#include "str.h" +#include "tab.h" #include "value-labels.h" #include "var.h" #include "vfm.h" -#include "hash.h" -#include "group_proc.h" -#include "casefile.h" -#include "levene.h" #include "gettext.h" #define _(msgid) gettext (msgid) @@ -440,11 +441,11 @@ static int tts_custom_pairs (struct cmd_t_test *cmd UNUSED) { struct variable **vars; - int n_vars; - int n_pairs_local; + size_t n_vars; + size_t n_pairs_local; - int n_before_WITH ; - int n_after_WITH = -1; + size_t n_before_WITH; + size_t n_after_WITH = SIZE_MAX; int paired ; /* Was the PAIRED keyword given ? */ lex_match('='); @@ -458,7 +459,7 @@ tts_custom_pairs (struct cmd_t_test *cmd UNUSED) } assert (n_vars); - n_before_WITH=0; + n_before_WITH = 0; if (lex_match (T_WITH)) { n_before_WITH = n_vars; @@ -486,11 +487,11 @@ tts_custom_pairs (struct cmd_t_test *cmd UNUSED) n_before_WITH, n_after_WITH ); return 0; } - n_pairs_local=n_before_WITH; + n_pairs_local = n_before_WITH; } else if (n_before_WITH > 0) /* WITH keyword given, but not PAIRED keyword */ { - n_pairs_local=n_before_WITH * n_after_WITH ; + n_pairs_local = n_before_WITH * n_after_WITH ; } else /* Neither WITH nor PAIRED keyword given */ { @@ -503,7 +504,7 @@ tts_custom_pairs (struct cmd_t_test *cmd UNUSED) } /* how many ways can you pick 2 from n_vars ? */ - n_pairs_local = n_vars * (n_vars -1 ) /2 ; + n_pairs_local = n_vars * (n_vars - 1) / 2; } @@ -515,17 +516,17 @@ tts_custom_pairs (struct cmd_t_test *cmd UNUSED) { int i; - assert(n_pairs_local == n_vars/2); - for (i = 0; i < n_pairs_local ; ++i) + assert(n_pairs_local == n_vars / 2); + for (i = 0; i < n_pairs_local; ++i) { - pairs[i].v[n_pairs+0] = vars[i]; - pairs[i].v[n_pairs+1] = vars[i+n_pairs_local]; + pairs[i].v[n_pairs] = vars[i]; + pairs[i].v[n_pairs + 1] = vars[i + n_pairs_local]; } } else if (n_before_WITH > 0) /* WITH keyword given, but not PAIRED keyword */ { int i,j; - int p=n_pairs; + size_t p = n_pairs; for(i=0 ; i < n_before_WITH ; ++i ) { @@ -539,8 +540,8 @@ tts_custom_pairs (struct cmd_t_test *cmd UNUSED) } else /* Neither WITH nor PAIRED given */ { - int i,j; - int p=n_pairs; + size_t i,j; + size_t p=n_pairs; for(i=0 ; i < n_vars ; ++i ) { @@ -889,7 +890,7 @@ ssbox_one_sample_populate(struct ssbox *ssb, struct cmd_t_test *cmd) /* Implementation of the Test Results box struct */ -void trbox_base_init(struct trbox *self,int n_vars, int cols); +void trbox_base_init(struct trbox *self,size_t n_vars, int cols); void trbox_base_finalize(struct trbox *trb); void trbox_independent_samples_init(struct trbox *trb, @@ -1317,9 +1318,9 @@ trbox_one_sample_populate(struct trbox *trb, struct cmd_t_test *cmd) /* Base initializer for the generalized trbox */ void -trbox_base_init(struct trbox *self, int data_rows, int cols) +trbox_base_init(struct trbox *self, size_t data_rows, int cols) { - const int rows = 3 + data_rows; + const size_t rows = 3 + data_rows; self->finalize = trbox_base_finalize; self->t = tab_create (cols, rows, 0); diff --git a/src/val-labs.c b/src/val-labs.c index 47d1ee65..657bf5c7 100644 --- a/src/val-labs.c +++ b/src/val-labs.c @@ -35,9 +35,9 @@ /* Declarations. */ static int do_value_labels (int); -static int verify_val_labs (struct variable **vars, int var_cnt); -static void erase_labels (struct variable **vars, int var_cnt); -static int get_label (struct variable **vars, int var_cnt); +static int verify_val_labs (struct variable **vars, size_t var_cnt); +static void erase_labels (struct variable **vars, size_t var_cnt); +static int get_label (struct variable **vars, size_t var_cnt); /* Stubs. */ @@ -59,7 +59,7 @@ static int do_value_labels (int erase) { struct variable **vars; /* Variable list. */ - int var_cnt; /* Number of variables. */ + size_t var_cnt; /* Number of variables. */ int parse_err=0; /* true if error parsing variables */ lex_match ('/'); @@ -108,9 +108,9 @@ do_value_labels (int erase) /* Verifies that none of the VAR_CNT variables in VARS are long string variables. */ static int -verify_val_labs (struct variable **vars, int var_cnt) +verify_val_labs (struct variable **vars, size_t var_cnt) { - int i; + size_t i; for (i = 0; i < var_cnt; i++) { @@ -128,9 +128,9 @@ verify_val_labs (struct variable **vars, int var_cnt) /* Erases all the labels for the VAR_CNT variables in VARS. */ static void -erase_labels (struct variable **vars, int var_cnt) +erase_labels (struct variable **vars, size_t var_cnt) { - int i; + size_t i; /* Erase old value labels if desired. */ for (i = 0; i < var_cnt; i++) @@ -140,14 +140,14 @@ erase_labels (struct variable **vars, int var_cnt) /* Parse all the labels for the VAR_CNT variables in VARS and add the specified labels to those variables. */ static int -get_label (struct variable **vars, int var_cnt) +get_label (struct variable **vars, size_t var_cnt) { /* Parse all the labels and add them to the variables. */ do { union value value; char *label; - int i; + size_t i; /* Set value. */ if (vars[0]->type == ALPHA) diff --git a/src/var-display.c b/src/var-display.c index 8243ac62..485fd3a1 100644 --- a/src/var-display.c +++ b/src/var-display.c @@ -39,9 +39,9 @@ cmd_variable_alignment (void) do { struct variable **v; - int nv; + size_t nv; - int i; + size_t i; enum alignment align; @@ -93,8 +93,8 @@ cmd_variable_width (void) do { struct variable **v; - int nv; - int i; + size_t nv; + size_t i; if (!parse_variables (default_dict, &v, &nv, PV_NONE)) return CMD_PART_SUCCESS_MAYBE; @@ -127,9 +127,9 @@ cmd_variable_level (void) do { struct variable **v; - int nv; + size_t nv; enum measure level; - int i; + size_t i; if (!parse_variables (default_dict, &v, &nv, PV_NONE)) return CMD_PART_SUCCESS_MAYBE; diff --git a/src/var-labs.c b/src/var-labs.c index 65da7908..3b5aa838 100644 --- a/src/var-labs.c +++ b/src/var-labs.c @@ -35,13 +35,13 @@ int cmd_variable_labels (void) { - struct variable **v; - int nv; - - int i; - do { + struct variable **v; + size_t nv; + + size_t i; + if (!parse_variables (default_dict, &v, &nv, PV_NONE)) return CMD_PART_SUCCESS_MAYBE; diff --git a/src/var.h b/src/var.h index b4d50182..672516c4 100644 --- a/src/var.h +++ b/src/var.h @@ -195,7 +195,8 @@ size_t var_set_get_cnt (const struct var_set *vs); struct variable *var_set_get_var (const struct var_set *vs, size_t idx); struct variable *var_set_lookup_var (const struct var_set *vs, const char *name); -int var_set_lookup_var_idx (const struct var_set *vs, const char *name); +bool var_set_lookup_var_idx (const struct var_set *vs, const char *name, + size_t *idx); void var_set_destroy (struct var_set *vs); /* Variable parsers. */ @@ -215,12 +216,12 @@ enum struct variable *parse_variable (void); struct variable *parse_dict_variable (const struct dictionary *); -int parse_variables (const struct dictionary *, struct variable ***, int *, +int parse_variables (const struct dictionary *, struct variable ***, size_t *, int opts); -int parse_var_set_vars (const struct var_set *, struct variable ***, int *, +int parse_var_set_vars (const struct var_set *, struct variable ***, size_t *, int opts); -int parse_DATA_LIST_vars (char ***names, int *cnt, int opts); -int parse_mixed_vars (char ***names, int *cnt, int opts); +int parse_DATA_LIST_vars (char ***names, size_t *cnt, int opts); +int parse_mixed_vars (char ***names, size_t *cnt, int opts); diff --git a/src/vars-prs.c b/src/vars-prs.c index 7a6e8633..37629604 100644 --- a/src/vars-prs.c +++ b/src/vars-prs.c @@ -20,6 +20,7 @@ #include #include "var.h" #include +#include #include #include "alloc.h" #include "bitvector.h" @@ -28,31 +29,35 @@ #include "hash.h" #include "lexer.h" #include "misc.h" +#include "size_max.h" #include "str.h" #include "gettext.h" #define _(msgid) gettext (msgid) -/* Parses a name as a variable within VS and returns the - variable's index if successful. On failure emits an error - message and returns a null pointer. */ -static int -parse_vs_variable_idx (const struct var_set *vs) +/* Parses a name as a variable within VS. Sets *IDX to the + variable's index and returns true if successful. On failure + emits an error message and returns false. */ +static bool +parse_vs_variable_idx (const struct var_set *vs, size_t *idx) { - int idx; - + assert (idx != NULL); + if (token != T_ID) { lex_error (_("expecting variable name")); - return -1; + return false; + } + else if (var_set_lookup_var_idx (vs, tokid, idx)) + { + lex_get (); + return true; + } + else + { + msg (SE, _("%s is not a variable name."), tokid); + return false; } - - idx = var_set_lookup_var_idx (vs, tokid); - if (idx < 0) - msg (SE, _("%s is not a variable name."), tokid); - lex_get (); - - return idx; } /* Parses a name as a variable within VS and returns the variable @@ -61,8 +66,8 @@ parse_vs_variable_idx (const struct var_set *vs) static struct variable * parse_vs_variable (const struct var_set *vs) { - int idx = parse_vs_variable_idx (vs); - return idx >= 0 ? var_set_get_var (vs, idx) : NULL; + size_t idx; + return parse_vs_variable_idx (vs, &idx) ? var_set_get_var (vs, idx) : NULL; } /* Parses a variable name in dictionary D and returns the @@ -128,7 +133,7 @@ dict_class_to_name (enum dict_class dict_class) successful. */ int parse_variables (const struct dictionary *d, struct variable ***var, - int *cnt, int opts) + size_t *cnt, int opts) { struct var_set *vs; int success; @@ -150,11 +155,10 @@ parse_variables (const struct dictionary *d, struct variable ***var, dictionary class, and returns nonzero. Returns zero on failure. */ static int -parse_var_idx_class (const struct var_set *vs, int *idx, +parse_var_idx_class (const struct var_set *vs, size_t *idx, enum dict_class *class) { - *idx = parse_vs_variable_idx (vs); - if (*idx < 0) + if (!parse_vs_variable_idx (vs, idx)) return 0; *class = dict_class_from_id (var_set_get_var (vs, *idx)->name); @@ -167,9 +171,9 @@ parse_var_idx_class (const struct var_set *vs, int *idx, PV_OPTS, which also affects what variables are allowed in appropriate ways. */ static void -add_variable (struct variable ***v, int *nv, int *mv, +add_variable (struct variable ***v, size_t *nv, size_t *mv, char *included, int pv_opts, - const struct var_set *vs, int idx) + const struct var_set *vs, size_t idx) { struct variable *add = var_set_get_var (vs, idx); @@ -213,12 +217,12 @@ add_variable (struct variable ***v, int *nv, int *mv, duplicates if indicated by PV_OPTS, which also affects what variables are allowed in appropriate ways. */ static void -add_variables (struct variable ***v, int *nv, int *mv, char *included, +add_variables (struct variable ***v, size_t *nv, size_t *mv, char *included, int pv_opts, const struct var_set *vs, int first_idx, int last_idx, enum dict_class class) { - int i; + size_t i; for (i = first_idx; i <= last_idx; i++) if (dict_class_from_id (var_set_get_var (vs, i)->name) == class) @@ -230,10 +234,10 @@ add_variables (struct variable ***v, int *nv, int *mv, char *included, nonzero and *v is non-NULL. */ int parse_var_set_vars (const struct var_set *vs, - struct variable ***v, int *nv, + struct variable ***v, size_t *nv, int pv_opts) { - int mv; + size_t mv; char *included; assert (vs != NULL); @@ -260,7 +264,7 @@ parse_var_set_vars (const struct var_set *vs, if (!(pv_opts & PV_DUPLICATE)) { - int i; + size_t i; included = xcalloc (var_set_get_cnt (vs), sizeof *included); for (i = 0; i < *nv; i++) @@ -277,17 +281,16 @@ parse_var_set_vars (const struct var_set *vs, do { enum dict_class class; - int first_idx; + size_t first_idx; if (!parse_var_idx_class (vs, &first_idx, &class)) goto fail; if (!lex_match (T_TO)) - add_variable (v, nv, &mv, included, pv_opts, - vs, first_idx); + add_variable (v, nv, &mv, included, pv_opts, vs, first_idx); else { - int last_idx; + size_t last_idx; enum dict_class last_class; struct variable *first_var, *last_var; @@ -388,12 +391,12 @@ extract_num (char *s, char *r, int *n, int *d) /* Parses a list of variable names according to the DATA LIST version of the TO convention. */ int -parse_DATA_LIST_vars (char ***names, int *nnames, int pv_opts) +parse_DATA_LIST_vars (char ***names, size_t *nnames, int pv_opts) { int n1, n2; int d1, d2; int n; - int nvar, mvar; + size_t nvar, mvar; char name1[LONG_NAME_LEN + 1], name2[LONG_NAME_LEN + 1]; char root1[LONG_NAME_LEN + 1], root2[LONG_NAME_LEN + 1]; int success = 0; @@ -505,9 +508,9 @@ fail: existing and the rest are to be created. Same args as parse_DATA_LIST_vars(). */ int -parse_mixed_vars (char ***names, int *nnames, int pv_opts) +parse_mixed_vars (char ***names, size_t *nnames, int pv_opts) { - int i; + size_t i; assert (names != NULL); assert (nnames != NULL); @@ -523,7 +526,7 @@ parse_mixed_vars (char ***names, int *nnames, int pv_opts) if (token == T_ALL || dict_lookup_var (default_dict, tokid) != NULL) { struct variable **v; - int nv; + size_t nv; if (!parse_variables (default_dict, &v, &nv, PV_NONE)) goto fail; @@ -552,7 +555,7 @@ struct var_set { size_t (*get_cnt) (const struct var_set *); struct variable *(*get_var) (const struct var_set *, size_t idx); - int (*lookup_var_idx) (const struct var_set *, const char *); + bool (*lookup_var_idx) (const struct var_set *, const char *, size_t *); void (*destroy) (struct var_set *); void *aux; }; @@ -582,20 +585,23 @@ var_set_get_var (const struct var_set *vs, size_t idx) struct variable * var_set_lookup_var (const struct var_set *vs, const char *name) { - int idx = var_set_lookup_var_idx (vs, name); - return idx >= 0 ? var_set_get_var (vs, idx) : NULL; + size_t idx; + return (var_set_lookup_var_idx (vs, name, &idx) + ? var_set_get_var (vs, idx) + : NULL); } -/* Returns the index in VS of the variable named NAME, or -1 if - VS contains no variable with that name. */ -int -var_set_lookup_var_idx (const struct var_set *vs, const char *name) +/* If VS contains a variable named NAME, sets *IDX to its index + and returns true. Otherwise, returns false. */ +bool +var_set_lookup_var_idx (const struct var_set *vs, const char *name, + size_t *idx) { assert (vs != NULL); assert (name != NULL); - assert (strlen (name) <= LONG_NAME_LEN ); + assert (strlen (name) <= LONG_NAME_LEN); - return vs->lookup_var_idx (vs, name); + return vs->lookup_var_idx (vs, name, idx); } /* Destroys VS. */ @@ -625,14 +631,21 @@ dict_var_set_get_var (const struct var_set *vs, size_t idx) return dict_get_var (d, idx); } -/* Returns the index of the variable in VS named NAME, or -1 if - VS contains no variable with that name. */ -static int -dict_var_set_lookup_var_idx (const struct var_set *vs, const char *name) +/* If VS contains a variable named NAME, sets *IDX to its index + and returns true. Otherwise, returns false. */ +static bool +dict_var_set_lookup_var_idx (const struct var_set *vs, const char *name, + size_t *idx) { struct dictionary *d = vs->aux; struct variable *v = dict_lookup_var (d, name); - return v != NULL ? v->index : -1; + if (v != NULL) + { + *idx = v->index; + return true; + } + else + return false; } /* Destroys VS. */ @@ -682,10 +695,11 @@ array_var_set_get_var (const struct var_set *vs, size_t idx) return (struct variable *) avs->var[idx]; } -/* Returns the index of the variable in VS named NAME, or -1 if - VS contains no variable with that name. */ -static int -array_var_set_lookup_var_idx (const struct var_set *vs, const char *name) +/* If VS contains a variable named NAME, sets *IDX to its index + and returns true. Otherwise, returns false. */ +static bool +array_var_set_lookup_var_idx (const struct var_set *vs, const char *name, + size_t *idx) { struct array_var_set *avs = vs->aux; struct variable v, *vp, *const *vpp; @@ -693,7 +707,13 @@ array_var_set_lookup_var_idx (const struct var_set *vs, const char *name) strcpy (v.name, name); vp = &v; vpp = hsh_find (avs->name_tab, &vp); - return vpp != NULL ? vpp - avs->var : -1; + if (vpp != NULL) + { + *idx = vpp - avs->var; + return true; + } + else + return false; } /* Destroys VS. */ diff --git a/src/vector.c b/src/vector.c index 1192252b..fc7a2dd3 100644 --- a/src/vector.c +++ b/src/vector.c @@ -89,7 +89,7 @@ cmd_vector (void) { /* Long form. */ struct variable **v; - int nv; + size_t nv; if (strchr (vecnames, '\0')[1]) {
%s