From: Joseph Myers Date: Wed, 18 Oct 2000 16:09:35 +0000 (+0100) Subject: c-common.c (check_format_types): Check for writing through a NULL pointer argument. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=81cf47b209c433b6cb1ccffb030789a06ffa5c16;p=gcc.git 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a78abfdea90..a3f14f9748e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2000-10-18 Joseph S. Myers + + * c-common.c (check_format_types): Check for writing through a + NULL pointer argument. + 2000-10-18 Hans-Peter Nilsson * tm.texi (Exception Region Output): Document diff --git a/gcc/c-common.c b/gcc/c-common.c index e9548dc1551..09cb949f439 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 b641c85d5a9..679b4edf630 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2000-10-18 Joseph S. Myers + + * 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 * 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 ef9e498e5bc..85193ec72e9 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 f1da57aff88..922a7a782bd 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" } */ }