summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/builtins.c5
2 files changed, 10 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index bfeb09aeab3..04f778f7bcc 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2004-07-09 Alexandre Oliva <aoliva@redhat.com>
+
+ * builtins.c (fold_builtin_strncpy): Make sure len is a constant
+ before comparing it as such.
+
2004-07-08 Richard Henderson <rth@redhat.com>
* builtins.c (std_gimplify_va_arg_expr): Hoist valist into a
diff --git a/gcc/builtins.c b/gcc/builtins.c
index ecb7841ec6d..11e1f05a0f9 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -7385,6 +7385,11 @@ fold_builtin_strncpy (tree exp, tree slen)
if (integer_zerop (len))
return omit_one_operand (TREE_TYPE (exp), dest, src);
+ /* We can't compare slen with len as constants below if len is not a
+ constant. */
+ if (len == 0 || TREE_CODE (len) != INTEGER_CST)
+ return 0;
+
if (!slen)
slen = c_strlen (src, 1);