From a9608b5743857c8e672f5e6437c25cf41a63c0cb Mon Sep 17 00:00:00 2001 From: Jerry DeLisle Date: Sun, 15 Jun 2008 20:02:58 +0000 Subject: [PATCH] re PR fortran/36515 (Integer read from stdin yields a value overflow for a valid integer.) 2008-06-15 Jerry DeLisle PR fortran/36515 * libgfortran.h (compile_options_t): Add int range_check to structure. * runtime/compile_options.c (set_options): Add range_check option. (init_compile_options): Likewise. *io/read.c (read_decimal): Change overflow checks to include range_check. From-SVN: r136822 --- libgfortran/ChangeLog | 9 +++++++++ libgfortran/io/read.c | 4 ++-- libgfortran/libgfortran.h | 1 + libgfortran/runtime/compile_options.c | 3 +++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index 0966d487457..f5b6a2731c0 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,12 @@ +2008-06-14 Jerry DeLisle + + PR fortran/36515 + * libgfortran.h (compile_options_t): Add int range_check to structure. + * runtime/compile_options.c (set_options): Add range_check option. + (init_compile_options): Likewise. + *io/read.c (read_decimal): Change overflow checks to include + range_check. + 2008-06-13 Jerry DeLisle PR fortran/36538 diff --git a/libgfortran/io/read.c b/libgfortran/io/read.c index 11a1ac018f7..cb88933bf97 100644 --- a/libgfortran/io/read.c +++ b/libgfortran/io/read.c @@ -428,13 +428,13 @@ read_decimal (st_parameter_dt *dtp, const fnode *f, char *dest, int length) if (c < '0' || c > '9') goto bad; - if (value > maxv_10) + if (value > maxv_10 && compile_options.range_check == 1) goto overflow; c -= '0'; value = 10 * value; - if (value > maxv - c) + if (value > maxv - c && compile_options.range_check == 1) goto overflow; value += c; } diff --git a/libgfortran/libgfortran.h b/libgfortran/libgfortran.h index 8c0f1b4a796..10439bd3e5a 100644 --- a/libgfortran/libgfortran.h +++ b/libgfortran/libgfortran.h @@ -477,6 +477,7 @@ typedef struct size_t record_marker; int max_subrecord_length; int bounds_check; + int range_check; } compile_options_t; diff --git a/libgfortran/runtime/compile_options.c b/libgfortran/runtime/compile_options.c index 8e0a3fe30ce..c62fe1c326a 100644 --- a/libgfortran/runtime/compile_options.c +++ b/libgfortran/runtime/compile_options.c @@ -105,6 +105,8 @@ set_options (int num, int options[]) compile_options.sign_zero = options[5]; if (num >= 7) compile_options.bounds_check = options[6]; + if (num >= 8) + compile_options.range_check = options[7]; /* If backtrace is required, we set signal handlers on most common signals. */ @@ -146,6 +148,7 @@ init_compile_options (void) compile_options.dump_core = 0; compile_options.backtrace = 0; compile_options.sign_zero = 1; + compile_options.range_check = 1; } /* Function called by the front-end to tell us the -- 2.30.2