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
This commit is contained in:
Joseph Myers 2000-10-18 17:09:35 +01:00 committed by Joseph Myers
parent 27c35f4b24
commit 81cf47b209
5 changed files with 22 additions and 1 deletions

View 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> 2000-10-18 Hans-Peter Nilsson <hp@axis.com>
* tm.texi (Exception Region Output): Document * tm.texi (Exception Region Output): Document

View File

@ -3119,6 +3119,15 @@ check_format_types (status, types)
if (TREE_CODE (cur_type) == ERROR_MARK) if (TREE_CODE (cur_type) == ERROR_MARK)
break; 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) if (cur_param != 0 && TREE_CODE (cur_param) == ADDR_EXPR)
cur_param = TREE_OPERAND (cur_param, 0); cur_param = TREE_OPERAND (cur_param, 0);
else else

View 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> 2000-10-17 Matthew Hiller <hiller@redhat.com>
* gcc.c-torture/execute/20001017-2.c: New test. * gcc.c-torture/execute/20001017-2.c: New test.

View 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 ("%++d", i); /* { dg-warning "repeated" "repeated flag warning" } */
printf ("%n", cn); /* { dg-warning "constant" "%n with const" } */ printf ("%n", cn); /* { dg-warning "constant" "%n with const" } */
printf ((const char *)L"foo"); /* { dg-warning "wide" "wide string" } */ 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" } */
} }

View 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 ("%d\0%d", ip, ip); /* { dg-warning "embedded|too many" "warning for embedded NUL" } */
scanf (NULL); /* { dg-warning "null" "null format string warning" } */ scanf (NULL); /* { dg-warning "null" "null format string warning" } */
scanf ("%"); /* { dg-warning "trailing" "trailing % warning" } */ scanf ("%"); /* { dg-warning "trailing" "trailing % warning" } */
scanf ("%d", (int *)0); /* { dg-warning "null" "writing into NULL" } */
} }