Bug 99615 - gcc/cp/decl.c:10038:possible null pointer dereference
Summary: gcc/cp/decl.c:10038:possible null pointer dereference
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 11.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: cppcheck
  Show dependency treegraph
 
Reported: 2021-03-16 11:20 UTC by David Binderman
Modified: 2021-03-17 05:01 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-03-16 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Binderman 2021-03-16 11:20:28 UTC
cppcheck says

trunk.git/gcc/cp/decl.c:10038:7: warning: Either the condition 'attrlist' is redundant or there is possible null pointer dereference: attrlist. [nullPointerRedundantCheck]

Source code is

  decl = check_explicit_specialization (orig_declarator, decl,
                                        template_count,
                                        2 * funcdef_flag +
                                        4 * (friendp != 0) +
                                        8 * concept_p,
                                        *attrlist);
  if (decl == error_mark_node)
    return NULL_TREE;

  if (DECL_STATIC_FUNCTION_P (decl))
    check_static_quals (decl, quals);

  if (attrlist)
    {
      cplus_decl_attributes (&decl, *attrlist, 0);
      *attrlist = NULL_TREE;
    }

Note how the variable attrlist is used as a pointer, *before*
it is later checked.

Another possibility is that the final if statement should be

  if (*attrlist)
Comment 1 Martin Liška 2021-03-16 12:19:18 UTC
It's very hairy code:

037cc9c5dce2 (Fariborz Jahanian         2004-09-23 18:22:25 +0000 10045)   if (attrlist)
037cc9c5dce2 (Fariborz Jahanian         2004-09-23 18:22:25 +0000 10046)     {
037cc9c5dce2 (Fariborz Jahanian         2004-09-23 18:22:25 +0000 10047)       cplus_decl_attributes (&decl, *attrlist, 0);
037cc9c5dce2 (Fariborz Jahanian         2004-09-23 18:22:25 +0000 10048)       *attrlist = NULL_TREE;
037cc9c5dce2 (Fariborz Jahanian         2004-09-23 18:22:25 +0000 10049)     }
037cc9c5dce2 (Fariborz Jahanian         2004-09-23 18:22:25 +0000 10050) 


but yes, I think it should be 'if (*attrlist)'.