From: Ben Pfaff Date: Wed, 11 May 2005 03:03:42 +0000 (+0000) Subject: Fix PR 13054. X-Git-Tag: v0.4.0~79 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2013acbcc3afa3f974de6ad335248e97a9c7b965;p=pspp-builds.git Fix PR 13054. --- diff --git a/src/ChangeLog b/src/ChangeLog index 6ee4db12..fbed36d0 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,15 @@ +Tue May 10 19:56:35 2005 Ben Pfaff + + Fix PR 13054. + + * format.c: (check_input_specifier) Improve error message. + (check_input_specifier) Check F, COMMA, and DOLLAR formats for + valid decimal places. + (check_output_specifier) Ditto (but different criteria). + (convert_fmt_ItoO) Assert valid input and output specifiers. + Also, if input specifier has *any* decimal places, make the output + specifier 1 place wider. + Mon May 9 07:14:29 WST 2005 John Darrington * sysfile-info.c: Fixed bug [# 13024 ] diff --git a/src/format.c b/src/format.c index b3070e21..9c6bbea4 100644 --- a/src/format.c +++ b/src/format.c @@ -157,7 +157,7 @@ check_input_specifier (const struct fmt_spec *spec, int emit_error) if (f->cat & FCAT_OUTPUT_ONLY) { if (emit_error) - msg (SE, _("Format %s may not be used as an input format."), f->name); + msg (SE, _("Format %s may not be used for input."), f->name); return 0; } if (spec->w < f->Imin_w || spec->w > f->Imax_w) @@ -168,6 +168,15 @@ check_input_specifier (const struct fmt_spec *spec, int emit_error) str, spec->w, f->name, f->Imin_w, f->Imax_w); return 0; } + if ((spec->type == FMT_F || spec->type == FMT_COMMA + || spec->type == FMT_DOLLAR) + && spec->d > spec->w) + { + if (emit_error) + msg (SE, _("Input format %s is invalid because it specifies more " + "decimal places than the field width."), str); + return 0; + } return 1; } @@ -192,16 +201,16 @@ check_output_specifier (const struct fmt_spec *spec, int emit_error) str, spec->w, f->name, f->Omin_w, f->Omax_w); return 0; } - if (spec->d > 1 - && (spec->type == FMT_F || spec->type == FMT_COMMA + if ((spec->type == FMT_F || spec->type == FMT_COMMA || spec->type == FMT_DOLLAR) - && spec->w < f->Omin_w + 1 + spec->d) + && spec->d >= spec->w) { if (emit_error) - msg (SE, _("Output format %s requires minimum width %d to allow " - "%d decimal places. Try %s%d.%d instead of %s."), - f->name, f->Omin_w + 1 + spec->d, spec->d, f->name, - f->Omin_w + 1 + spec->d, spec->d, str); + msg (SE, _("Output format %s is invalid because it specifies as " + "many decimal places as the field width, which " + "fails to allow space for a decimal point. " + "Try %s%d.%d instead."), + str, f->name, f->name, spec->d + 1, spec->d); return 0; } return 1; @@ -253,6 +262,8 @@ check_specifier_width (const struct fmt_spec *format, void convert_fmt_ItoO (const struct fmt_spec *input, struct fmt_spec *output) { + assert (check_input_specifier (input, 0)); + output->type = formats[input->type].output; output->w = input->w; if (output->w > formats[output->type].Omax_w) @@ -263,8 +274,8 @@ convert_fmt_ItoO (const struct fmt_spec *input, struct fmt_spec *output) { case FMT_F: case FMT_N: - if (output->d > 1 && output->w < 2 + output->d) - output->w = 2 + output->d; + if (output->d > 0) + output->w++; break; case FMT_E: output->w = max (max (input->w, input->d+7), 10); @@ -340,6 +351,8 @@ convert_fmt_ItoO (const struct fmt_spec *input, struct fmt_spec *output) default: assert (0); } + + assert (check_output_specifier (output, 0)); } /* Parses a format specifier from the token stream and returns diff --git a/tests/ChangeLog b/tests/ChangeLog index a45dfd3f..0c7d6722 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,7 @@ +Tue May 10 19:59:10 2005 Ben Pfaff + + * bugs/agg-crash-2.sh: Fix output given PR 13054. + Wed May 4 23:50:02 2005 Ben Pfaff * bugs/match-files-scratch.sh: New test for PR 12948. diff --git a/tests/bugs/agg-crash-2.sh b/tests/bugs/agg-crash-2.sh index ff2a1e5d..1f67dd35 100755 --- a/tests/bugs/agg-crash-2.sh +++ b/tests/bugs/agg-crash-2.sh @@ -76,10 +76,10 @@ diff -b -B -w $TEMPDIR/pspp.list - << EOF |Y |A25 | +--------+------+ - X Y --------- ------------------------- - 87.34 bar - 87.50 foo + X Y +--------- ------------------------- + 87.34 bar + 87.50 foo EOF if [ $? -ne 0 ] ; then fail ; fi