diff options
author | François-Xavier Coudert <fxcoudert@gcc.gnu.org> | 2021-12-16 18:38:30 +0100 |
---|---|---|
committer | François-Xavier Coudert <fxcoudert@gcc.gnu.org> | 2021-12-18 09:21:16 +0100 |
commit | 21423a1dfa079d4cd218f69d2fab9fe65a69fedb (patch) | |
tree | 08f1191472543839ad785d3bc99b304118528fba /libgfortran/runtime/environ.c | |
parent | f18cbc1ee1f421a0dd79dc389bef9a23dd4a761d (diff) | |
download | gcc-21423a1dfa079d4cd218f69d2fab9fe65a69fedb.zip gcc-21423a1dfa079d4cd218f69d2fab9fe65a69fedb.tar.gz gcc-21423a1dfa079d4cd218f69d2fab9fe65a69fedb.tar.bz2 |
Fortran: Cast arguments of <ctype.h> functions to unsigned char
Functions from <ctype.h> should only be called on values that can be
represented by unsigned char. On targets where char is a signed type,
some of libgfortran calls have undefined behaviour.
The solution is to cast the argument to unsigned char type. I’ve defined
macros in libgfortran.h to do so, to retain legibility of the library
code.
PR libfortran/95177
libgfortran/ChangeLog
* libgfortran.h: include ctype.h, provide safe macros.
* io/format.c: use safe macros.
* io/list_read.c: use safe macros.
* io/read.c: use safe macros.
* io/write.c: use safe macros.
* runtime/environ.c: use safe macros.
Diffstat (limited to 'libgfortran/runtime/environ.c')
-rw-r--r-- | libgfortran/runtime/environ.c | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/libgfortran/runtime/environ.c b/libgfortran/runtime/environ.c index fe16c08..ce408cf 100644 --- a/libgfortran/runtime/environ.c +++ b/libgfortran/runtime/environ.c @@ -26,7 +26,6 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include <string.h> #include <strings.h> -#include <ctype.h> #ifdef HAVE_UNISTD_H #include <unistd.h> @@ -91,7 +90,7 @@ init_integer (variable * v) return; for (q = p; *q; q++) - if (!isdigit (*q) && (p != q || *q != '-')) + if (!safe_isdigit (*q) && (p != q || *q != '-')) return; *v->var = atoi (p); @@ -344,7 +343,7 @@ static int match_integer (void) { unit_num = 0; - while (isdigit (*p)) + while (safe_isdigit (*p)) unit_num = unit_num * 10 + (*p++ - '0'); return INTEGER; } |