X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Fformat.c;h=cce8c46ed2def8225719b514f30a777cfbb029b3;hb=5c5204d433be6419112bd77f75b9a9adb642f766;hp=5ee7ace500911893f24b559a967bd78812793f99;hpb=65620ac48c2b146a580a80af120590e4e3d4a6d4;p=pspp diff --git a/src/format.c b/src/format.c index 5ee7ace500..cce8c46ed2 100644 --- a/src/format.c +++ b/src/format.c @@ -23,7 +23,7 @@ #include "error.h" #include #include "error.h" -#include "lexer.h" +#include "lex-def.h" #include "misc.h" #include "str.h" #include "var.h" @@ -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)