aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJoseph Myers <jsm28@cam.ac.uk>2000-10-18 17:09:35 +0100
committerJoseph Myers <jsm28@gcc.gnu.org>2000-10-18 17:09:35 +0100
commit81cf47b209c433b6cb1ccffb030789a06ffa5c16 (patch)
tree85c536f50f4a4636eb737ad764e804903e9b46cd /gcc
parent27c35f4b2435bc05271dca75ec26a585e6853f4a (diff)
downloadgcc-81cf47b209c433b6cb1ccffb030789a06ffa5c16.zip
gcc-81cf47b209c433b6cb1ccffb030789a06ffa5c16.tar.gz
gcc-81cf47b209c433b6cb1ccffb030789a06ffa5c16.tar.bz2
c-common.c (check_format_types): Check for writing through a NULL pointer argument.
* c-common.c (check_format_types): Check for writing through a NULL pointer argument. testsuite: * gcc.dg/c90-printf-1.c, gcc.dg/c90-scanf-1.c: Add tests for writing through null pointers; remove comment about testing unterminated strings. From-SVN: r36936
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/c-common.c9
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/gcc.dg/c90-printf-1.c2
-rw-r--r--gcc/testsuite/gcc.dg/c90-scanf-1.c1
5 files changed, 22 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index a78abfd..a3f14f9 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2000-10-18 Joseph S. Myers <jsm28@cam.ac.uk>
+
+ * c-common.c (check_format_types): Check for writing through a
+ NULL pointer argument.
+
2000-10-18 Hans-Peter Nilsson <hp@axis.com>
* tm.texi (Exception Region Output): Document
diff --git a/gcc/c-common.c b/gcc/c-common.c
index e9548dc..09cb949 100644
--- a/gcc/c-common.c
+++ b/gcc/c-common.c
@@ -3119,6 +3119,15 @@ check_format_types (status, types)
if (TREE_CODE (cur_type) == ERROR_MARK)
break;
+ /* Check for writing through a NULL pointer. */
+ if (types->writing_in_flag
+ && i == 0
+ && cur_param != 0
+ && integer_zerop (cur_param))
+ status_warning (status,
+ "writing through null pointer (arg %d)",
+ arg_num);
+
if (cur_param != 0 && TREE_CODE (cur_param) == ADDR_EXPR)
cur_param = TREE_OPERAND (cur_param, 0);
else
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index b641c85..679b4ed 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2000-10-18 Joseph S. Myers <jsm28@cam.ac.uk>
+
+ * gcc.dg/c90-printf-1.c, gcc.dg/c90-scanf-1.c: Add tests for
+ writing through null pointers; remove comment about testing
+ unterminated strings.
+
2000-10-17 Matthew Hiller <hiller@redhat.com>
* gcc.c-torture/execute/20001017-2.c: New test.
diff --git a/gcc/testsuite/gcc.dg/c90-printf-1.c b/gcc/testsuite/gcc.dg/c90-printf-1.c
index ef9e498..85193ec 100644
--- a/gcc/testsuite/gcc.dg/c90-printf-1.c
+++ b/gcc/testsuite/gcc.dg/c90-printf-1.c
@@ -244,5 +244,5 @@ foo (int i, int i1, int i2, unsigned int u, double d, char *s, void *p,
printf ("%++d", i); /* { dg-warning "repeated" "repeated flag warning" } */
printf ("%n", cn); /* { dg-warning "constant" "%n with const" } */
printf ((const char *)L"foo"); /* { dg-warning "wide" "wide string" } */
- /* Can we test for the warning for unterminated string formats? */
+ printf ("%n", (int *)0); /* { dg-warning "null" "%n with NULL" } */
}
diff --git a/gcc/testsuite/gcc.dg/c90-scanf-1.c b/gcc/testsuite/gcc.dg/c90-scanf-1.c
index f1da57a..922a7a7 100644
--- a/gcc/testsuite/gcc.dg/c90-scanf-1.c
+++ b/gcc/testsuite/gcc.dg/c90-scanf-1.c
@@ -122,4 +122,5 @@ foo (int *ip, unsigned int *uip, short int *hp, unsigned short int *uhp,
scanf ("%d\0%d", ip, ip); /* { dg-warning "embedded|too many" "warning for embedded NUL" } */
scanf (NULL); /* { dg-warning "null" "null format string warning" } */
scanf ("%"); /* { dg-warning "trailing" "trailing % warning" } */
+ scanf ("%d", (int *)0); /* { dg-warning "null" "writing into NULL" } */
}