aboutsummaryrefslogtreecommitdiff
path: root/gcc/gimple-ssa-sprintf.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2019-04-10 09:27:20 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2019-04-10 09:27:20 +0200
commitc9c5e18883125c90b3cbdb61b651719253a0ff90 (patch)
tree00926960cbc7944e903ff64d68d4c2c050f5b285 /gcc/gimple-ssa-sprintf.c
parent7e1ab2dc3f5e9d59ecff8275fc107b126248048a (diff)
downloadgcc-c9c5e18883125c90b3cbdb61b651719253a0ff90.zip
gcc-c9c5e18883125c90b3cbdb61b651719253a0ff90.tar.gz
gcc-c9c5e18883125c90b3cbdb61b651719253a0ff90.tar.bz2
re PR c++/90010 (valgrind error with snprintf and -Wall)
PR c++/90010 * gimple-ssa-sprintf.c (target_to_host): Fix handling of targstr with strlen in between hostsz-3 and hostsz-1 inclusive when no translation is needed, and when translation is needed, only append ... if the string length is hostsz or more bytes long. Avoid using strncpy or strcat. * gcc.dg/pr90010.c: New test. From-SVN: r270246
Diffstat (limited to 'gcc/gimple-ssa-sprintf.c')
-rw-r--r--gcc/gimple-ssa-sprintf.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/gcc/gimple-ssa-sprintf.c b/gcc/gimple-ssa-sprintf.c
index de60241..b6527bf 100644
--- a/gcc/gimple-ssa-sprintf.c
+++ b/gcc/gimple-ssa-sprintf.c
@@ -383,9 +383,14 @@ target_to_host (char *hostr, size_t hostsz, const char *targstr)
overlong strings just like the translated strings are. */
if (target_to_host_charmap['\0'] == 1)
{
- strncpy (hostr, targstr, hostsz - 4);
- if (strlen (targstr) >= hostsz)
- strcpy (hostr + hostsz - 4, "...");
+ size_t len = strlen (targstr);
+ if (len >= hostsz)
+ {
+ memcpy (hostr, targstr, hostsz - 4);
+ strcpy (hostr + hostsz - 4, "...");
+ }
+ else
+ memcpy (hostr, targstr, len + 1);
return hostr;
}
@@ -399,10 +404,9 @@ target_to_host (char *hostr, size_t hostsz, const char *targstr)
if (!*targstr)
break;
- if (size_t (ph - hostr) == hostsz - 4)
+ if (size_t (ph - hostr) == hostsz)
{
- *ph = '\0';
- strcat (ph, "...");
+ strcpy (ph - 4, "...");
break;
}
}