diff options
author | Janne Blomqvist <jb@gcc.gnu.org> | 2011-01-22 00:42:17 +0200 |
---|---|---|
committer | Janne Blomqvist <jb@gcc.gnu.org> | 2011-01-22 00:42:17 +0200 |
commit | 723553bdc16695ecc686a2ffdff6d15bd600b676 (patch) | |
tree | 5760ecd6dfee3b5a3fbd1f7c8131d34047951c44 /libgfortran/intrinsics | |
parent | 62f9aedcd0a97001f290a1c13fa66efd207a23cc (diff) | |
download | gcc-723553bdc16695ecc686a2ffdff6d15bd600b676.zip gcc-723553bdc16695ecc686a2ffdff6d15bd600b676.tar.gz gcc-723553bdc16695ecc686a2ffdff6d15bd600b676.tar.bz2 |
PR 46267 strerror thread safety
From-SVN: r169110
Diffstat (limited to 'libgfortran/intrinsics')
-rw-r--r-- | libgfortran/intrinsics/gerror.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/libgfortran/intrinsics/gerror.c b/libgfortran/intrinsics/gerror.c index ccb5c3e..6feadc9 100644 --- a/libgfortran/intrinsics/gerror.c +++ b/libgfortran/intrinsics/gerror.c @@ -43,16 +43,17 @@ PREFIX(gerror) (char * msg, gfc_charlen_type msg_len) int p_len; char *p; - memset (msg, ' ', msg_len); /* Blank the string. */ - - p = strerror (errno); - if (p == NULL) - return; - + p = gf_strerror (errno, msg, msg_len); p_len = strlen (p); - if (msg_len < p_len) - memcpy (msg, p, msg_len); - else - memcpy (msg, p, p_len); + /* The returned pointer p might or might not be the same as the msg + argument. */ + if (p != msg) + { + if (msg_len < p_len) + p_len = msg_len; + memcpy (msg, p, p_len); + } + if (msg_len > p_len) + memset (&msg[p_len], ' ', msg_len - p_len); } #endif |