aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-family/c-warn.c
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2021-02-12 11:18:17 -0700
committerMartin Sebor <msebor@redhat.com>2021-02-12 11:18:52 -0700
commitf3d7fd1475eb1ed2b3a39f988b33db176d4f7419 (patch)
treef74f6efb9920e4f76d0dff24993adf4917e026b8 /gcc/c-family/c-warn.c
parent0631e008adc759cc801d0d034224ee6b4bcf31aa (diff)
downloadgcc-f3d7fd1475eb1ed2b3a39f988b33db176d4f7419.zip
gcc-f3d7fd1475eb1ed2b3a39f988b33db176d4f7419.tar.gz
gcc-f3d7fd1475eb1ed2b3a39f988b33db176d4f7419.tar.bz2
PR c/99055 - memory leak in warn_parm_array_mismatch
gcc/c-family/ChangeLog: PR c/99055 * c-warn.c (warn_parm_array_mismatch): Free strings returned from print_generic_expr_to_str. gcc/ChangeLog: * tree-pretty-print.c (print_generic_expr_to_str): Update comment.
Diffstat (limited to 'gcc/c-family/c-warn.c')
-rw-r--r--gcc/c-family/c-warn.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/gcc/c-family/c-warn.c b/gcc/c-family/c-warn.c
index e6e28d9..2347e0b 100644
--- a/gcc/c-family/c-warn.c
+++ b/gcc/c-family/c-warn.c
@@ -3319,6 +3319,19 @@ warn_parm_ptrarray_mismatch (location_t origloc, tree curparms, tree newparms)
}
}
+/* Format EXPR if nonnull and return the formatted string. If EXPR is
+ null return DFLT. */
+
+static inline const char*
+expr_to_str (pretty_printer &pp, tree expr, const char *dflt)
+{
+ if (!expr)
+ return dflt;
+
+ dump_generic_node (&pp, expr, 0, TDF_VOPS | TDF_MEMSYMS, false);
+ return pp_formatted_text (&pp);
+}
+
/* Detect and diagnose a mismatch between an attribute access specification
on the original declaration of FNDECL and that on the parameters NEWPARMS
from its refeclaration. ORIGLOC is the location of the first declaration
@@ -3585,10 +3598,9 @@ warn_parm_array_mismatch (location_t origloc, tree fndecl, tree newparms)
the same. */
continue;
- const char* const newbndstr =
- newbnd ? print_generic_expr_to_str (newbnd) : "*";
- const char* const curbndstr =
- curbnd ? print_generic_expr_to_str (curbnd) : "*";
+ pretty_printer pp1, pp2;
+ const char* const newbndstr = expr_to_str (pp1, newbnd, "*");
+ const char* const curbndstr = expr_to_str (pp2, curbnd, "*");
if (!newpos != !curpos
|| (newpos && !tree_int_cst_equal (newpos, curpos)))