X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=inline;f=src%2Fformat.c;h=cce8c46ed2def8225719b514f30a777cfbb029b3;hb=5c5204d433be6419112bd77f75b9a9adb642f766;hp=1c09e26c395bf5f6fc2f368392ce9f5ac2f38330;hpb=6ac27d1da3fdebee275343fcf7b6625fc1f1da79;p=pspp diff --git a/src/format.c b/src/format.c index 1c09e26c39..cce8c46ed2 100644 --- a/src/format.c +++ b/src/format.c @@ -64,8 +64,19 @@ fmt_to_string (const struct fmt_spec *f) static bool check_common_specifier (const struct fmt_spec *spec, bool emit_error) { - struct fmt_desc *f = &formats[spec->type]; - char *str = fmt_to_string (spec); + struct fmt_desc *f ; + char *str; + + if ( spec->type > FMT_NUMBER_OF_FORMATS ) + { + if (emit_error) + msg (SE, _("Format specifies a bad type (%d)"), spec->type); + + return false; + } + + f = &formats[spec->type]; + str = fmt_to_string (spec); if ((f->cat & FCAT_EVEN_WIDTH) && spec->w % 2) { @@ -92,11 +103,16 @@ check_common_specifier (const struct fmt_spec *spec, bool emit_error) int check_input_specifier (const struct fmt_spec *spec, int emit_error) { - struct fmt_desc *f = &formats[spec->type]; - char *str = fmt_to_string (spec); + struct fmt_desc *f ; + char *str ; if (!check_common_specifier (spec, emit_error)) return false; + + f = &formats[spec->type]; + str = fmt_to_string (spec); + + if (spec->type == FMT_X) return 1; if (f->cat & FCAT_OUTPUT_ONLY) @@ -131,11 +147,15 @@ check_input_specifier (const struct fmt_spec *spec, int emit_error) int check_output_specifier (const struct fmt_spec *spec, int emit_error) { - struct fmt_desc *f = &formats[spec->type]; - char *str = fmt_to_string (spec); + struct fmt_desc *f; + char *str ; if (!check_common_specifier (spec, emit_error)) return false; + + f = &formats[spec->type]; + str = fmt_to_string (spec); + if (spec->type == FMT_X) return 1; if (spec->w < f->Omin_w || spec->w > f->Omax_w)