aboutsummaryrefslogtreecommitdiff
path: root/libgfortran/io/write.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/write.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/write.c')
-rw-r--r--libgfortran/io/write.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/libgfortran/io/write.c b/libgfortran/io/write.c
index 278cd47..b9e9284 100644
--- a/libgfortran/io/write.c
+++ b/libgfortran/io/write.c
@@ -30,7 +30,6 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#include "unix.h"
#include <assert.h>
#include <string.h>
-#include <ctype.h>
#define star_fill(p, n) memset(p, '*', n)
@@ -2101,14 +2100,14 @@ nml_write_obj (st_parameter_dt *dtp, namelist_info *obj, index_type offset,
base_name_len = strlen (base_name);
for (dim_i = 0; dim_i < base_name_len; dim_i++)
{
- cup = toupper ((int) base_name[dim_i]);
+ cup = safe_toupper (base_name[dim_i]);
write_character (dtp, &cup, 1, 1, NODELIM);
}
}
clen = strlen (obj->var_name);
for (dim_i = len; dim_i < clen; dim_i++)
{
- cup = toupper ((int) obj->var_name[dim_i]);
+ cup = safe_toupper (obj->var_name[dim_i]);
if (cup == '+')
cup = '%';
write_character (dtp, &cup, 1, 1, NODELIM);
@@ -2426,7 +2425,7 @@ namelist_write (st_parameter_dt *dtp)
/* Write namelist name in upper case - f95 std. */
for (gfc_charlen_type i = 0; i < dtp->namelist_name_len; i++ )
{
- c = toupper ((int) dtp->namelist_name[i]);
+ c = safe_toupper (dtp->namelist_name[i]);
write_character (dtp, &c, 1 ,1, NODELIM);
}