c-common.c (check_format_types): Check for writing through a NULL pointer argument.
authorJoseph Myers <jsm28@cam.ac.uk>
Wed, 18 Oct 2000 16:09:35 +0000 (17:09 +0100)
committerJoseph Myers <jsm28@gcc.gnu.org>
Wed, 18 Oct 2000 16:09:35 +0000 (17:09 +0100)
* 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

gcc/ChangeLog
gcc/c-common.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/c90-printf-1.c
gcc/testsuite/gcc.dg/c90-scanf-1.c

index a78abfdea90106bccc16425da38cfab3e72a267e..a3f14f9748e2697481d63e9f7cd4b457920f48a3 100644 (file)
@@ -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
index e9548dc155143454d40f45fea32feab1b64dc72a..09cb949f4391f8332ad9b81116e6283c88b2ad3e 100644 (file)
@@ -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
index b641c85d5a9edca4cee0e4a806b99451d58438eb..679b4edf630432d33426ca613342aca05f81777b 100644 (file)
@@ -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.
index ef9e498e5bce0a42d2ce1df9a50397cb049e825a..85193ec72e9b647168cd1e799202987f9787eefa 100644 (file)
@@ -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" } */
 }
index f1da57aff88f1f53a8d288e15c4f775f5ccd4d89..922a7a782bd61311ce1d63224fa8f0e71a989772 100644 (file)
@@ -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" } */
 }