summaryrefslogtreecommitdiff
path: root/gcc/expr.c
diff options
context:
space:
mode:
authorMartin Sebor <msebor@gcc.gnu.org>2018-11-26 16:55:36 -0700
committerMartin Sebor <msebor@gcc.gnu.org>2018-11-26 16:55:36 -0700
commit67b9fab0e6f9fac918523df18ae2d8bbb88d7748 (patch)
treeffa797b2d0da859bb2520ba77e94369df8fecf3e /gcc/expr.c
parent426a04b84f4fed696149d8ba980dd48c6eb49de7 (diff)
PR 87756 - missing unterminated argument warning using address of a constant character
gcc/ChangeLog: PR 87756 * expr.c (string_constant): Handle top-level decls of all character types and subobjects of narrow character type. gcc/testsuite/ChangeLog: PR 87756 * gcc.dg/warn-sprintf-no-nul-2.c: Move incomplete tests from here... * gcc.dg/warn-sprintf-no-nul-3.c: ...to here and complete them. From-SVN: r266494
Diffstat (limited to 'gcc/expr.c')
-rw-r--r--gcc/expr.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/gcc/expr.c b/gcc/expr.c
index 021a04c5944..ef29ec5c40a 100644
--- a/gcc/expr.c
+++ b/gcc/expr.c
@@ -11497,10 +11497,16 @@ string_constant (tree arg, tree *ptr_offset, tree *mem_size, tree *decl)
if (decl)
*decl = array;
- if (TREE_CODE (init) == INTEGER_CST)
+ if (TREE_CODE (init) == INTEGER_CST
+ && (TREE_CODE (TREE_TYPE (array)) == INTEGER_TYPE
+ || TYPE_MAIN_VARIANT (eltype) == char_type_node))
{
/* For a reference to (address of) a single constant character,
- store the native representation of the character in CHARBUF. */
+ store the native representation of the character in CHARBUF.
+ If the reference is to an element of an array or a member
+ of a struct, only consider narrow characters until ctors
+ for wide character arrays are transformed to STRING_CSTs
+ like those for narrow arrays. */
unsigned char charbuf[MAX_BITSIZE_MODE_ANY_MODE / BITS_PER_UNIT];
int len = native_encode_expr (init, charbuf, sizeof charbuf, 0);
if (len > 0)