toplev.c: Check for null argument to fprintf
authorStefan Schulze Frielinghaus <stefansf@linux.ibm.com>
Sun, 26 Apr 2020 07:26:39 +0000 (09:26 +0200)
committerStefan Schulze Frielinghaus <stefansf@linux.ibm.com>
Thu, 30 Apr 2020 05:53:02 +0000 (07:53 +0200)
Ensure that CF does not equal NULL in function output_stack_usage_1
before calling fprintf.  This fixes the following warning/error:

gcc/toplev.c:976:13: error: argument 1 null where non-null expected [-Werror=nonnull]
  976 |     fprintf (cf, "\\n" HOST_WIDE_INT_PRINT_DEC " bytes (%s)",
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  977 |       stack_usage,
      |       ~~~~~~~~~~~~
  978 |       stack_usage_kind_str[stack_usage_kind]);

An example call side where CF is NULL is in function output_stack_usage.

gcc/ChangeLog:

2020-04-30  Stefan Schulze Frielinghaus  <stefansf@linux.ibm.com>

* toplev.c (output_stack_usage_1): Ensure that first
argument to fprintf is not null.

gcc/ChangeLog
gcc/toplev.c

index fc15925aa56f74af7ae87a9a6d7f81ed76a2e3c0..8abb4c0eda423704cd31178264d4944fe2f1a303 100644 (file)
@@ -1,3 +1,8 @@
+2020-04-30  Stefan Schulze Frielinghaus  <stefansf@linux.ibm.com>
+
+       * toplev.c (output_stack_usage_1): Ensure that first
+       argument to fprintf is not null.
+
 2020-04-29  Jakub Jelinek  <jakub@redhat.com>
 
        * configure.ac (-with-changes-root-url): New configure option,
index 4c8be502c719b9242f757bfe740ff571dda84998..5c026feece28c6527ab04459626d0376c22013d1 100644 (file)
@@ -972,7 +972,7 @@ output_stack_usage_1 (FILE *cf)
       stack_usage += current_function_dynamic_stack_size;
     }
 
-  if (flag_callgraph_info & CALLGRAPH_INFO_STACK_USAGE)
+  if (cf && flag_callgraph_info & CALLGRAPH_INFO_STACK_USAGE)
     fprintf (cf, "\\n" HOST_WIDE_INT_PRINT_DEC " bytes (%s)",
             stack_usage,
             stack_usage_kind_str[stack_usage_kind]);