aboutsummaryrefslogtreecommitdiff
path: root/gcc/gensupport.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2016-09-05 10:50:29 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2016-09-05 10:50:29 +0200
commitc5cb79681df13acc02894b4df8314c797895e2bb (patch)
tree8efaaa9001cb2afb2b1220c02be58020e4daf705 /gcc/gensupport.c
parent61f46d0e6dd5688e2a1e8cf1d45f92cf7182bac7 (diff)
downloadgcc-c5cb79681df13acc02894b4df8314c797895e2bb.zip
gcc-c5cb79681df13acc02894b4df8314c797895e2bb.tar.gz
gcc-c5cb79681df13acc02894b4df8314c797895e2bb.tar.bz2
re PR other/77421 (Bugs found in GCC with the help of PVS-Studio)
PR other/77421 * gensupport.c (alter_output_for_subst_insn): Remove redundant *insn_out == '*' test. Don't copy unnecessary to yet another memory buffer, and don't leak it. From-SVN: r239987
Diffstat (limited to 'gcc/gensupport.c')
-rw-r--r--gcc/gensupport.c29
1 files changed, 13 insertions, 16 deletions
diff --git a/gcc/gensupport.c b/gcc/gensupport.c
index 7e3aad3..4645ead 100644
--- a/gcc/gensupport.c
+++ b/gcc/gensupport.c
@@ -1632,33 +1632,30 @@ duplicate_each_alternative (const char * str, int n_dup)
static const char *
alter_output_for_subst_insn (rtx insn, int alt)
{
- const char *insn_out, *sp ;
- char *old_out, *new_out, *cp;
- int i, j, new_len;
+ const char *insn_out, *old_out;
+ char *new_out, *cp;
+ size_t old_len, new_len;
+ int j;
insn_out = XTMPL (insn, 3);
- if (alt < 2 || *insn_out == '*' || *insn_out != '@')
+ if (alt < 2 || *insn_out != '@')
return insn_out;
- old_out = XNEWVEC (char, strlen (insn_out)),
- sp = insn_out;
+ old_out = insn_out + 1;
+ while (ISSPACE (*old_out))
+ old_out++;
+ old_len = strlen (old_out);
- while (ISSPACE (*sp) || *sp == '@')
- sp++;
-
- for (i = 0; *sp;)
- old_out[i++] = *sp++;
-
- new_len = alt * (i + 1) + 1;
+ new_len = alt * (old_len + 1) + 1;
new_out = XNEWVEC (char, new_len);
new_out[0] = '@';
- for (j = 0, cp = new_out + 1; j < alt; j++, cp += i + 1)
+ for (j = 0, cp = new_out + 1; j < alt; j++, cp += old_len + 1)
{
- memcpy (cp, old_out, i);
- *(cp+i) = (j == alt - 1) ? '\0' : '\n';
+ memcpy (cp, old_out, old_len);
+ cp[old_len] = (j == alt - 1) ? '\0' : '\n';
}
return new_out;