aboutsummaryrefslogtreecommitdiff
path: root/libgfortran/io/read.c
diff options
context:
space:
mode:
authorFrançois-Xavier Coudert <fxcoudert@gcc.gnu.org>2021-12-16 18:38:30 +0100
committerFrançois-Xavier Coudert <fxcoudert@gcc.gnu.org>2021-12-18 09:21:16 +0100
commit21423a1dfa079d4cd218f69d2fab9fe65a69fedb (patch)
tree08f1191472543839ad785d3bc99b304118528fba /libgfortran/io/read.c
parentf18cbc1ee1f421a0dd79dc389bef9a23dd4a761d (diff)
downloadgcc-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/io/read.c')
-rw-r--r--libgfortran/io/read.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/libgfortran/io/read.c b/libgfortran/io/read.c
index 7515d91..7b3f137 100644
--- a/libgfortran/io/read.c
+++ b/libgfortran/io/read.c
@@ -28,7 +28,6 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#include "format.h"
#include "unix.h"
#include <string.h>
-#include <ctype.h>
#include <assert.h>
#include "async.h"
@@ -959,7 +958,7 @@ read_f (st_parameter_dt *dtp, const fnode *f, char *dest, int length)
between "NaN" and the optional perenthesis is not permitted. */
while (w > 0)
{
- *out = tolower (*p);
+ *out = safe_tolower (*p);
switch (*p)
{
case ' ':
@@ -981,7 +980,7 @@ read_f (st_parameter_dt *dtp, const fnode *f, char *dest, int length)
goto bad_float;
break;
default:
- if (!isalnum (*out))
+ if (!safe_isalnum (*out))
goto bad_float;
}
--w;
@@ -1109,7 +1108,7 @@ exponent:
if (dtp->u.p.blank_status == BLANK_UNSPECIFIED)
{
- while (w > 0 && isdigit (*p))
+ while (w > 0 && safe_isdigit (*p))
{
exponent *= 10;
exponent += *p - '0';
@@ -1137,7 +1136,7 @@ exponent:
else
assert (dtp->u.p.blank_status == BLANK_NULL);
}
- else if (!isdigit (*p))
+ else if (!safe_isdigit (*p))
goto bad_float;
else
{