Sitelet https://github.com/github/codeql/issues/7035
Skip to content

LGTM.com - false positive for move and copy assignment operators not returning *this (C++) #7035

Open

Description

@oknenavin

The error is reported for these operators when *this is returned indirectly via a function call. For example:

https://lgtm.com/projects/g/oknenavin/cxon/snapshot/9103621a01a81595999681a97870d8930d56aa58/files/src/cxon/lang/cbor/node/node.hxx?sort=name&dir=ASC&mode=heatmap#xc6e83398218bd018:1

we have:

return value::move_assign<T>(*this, std::forward<basic_node>(o));

where value::move_assign returns its first argument, which is *this.

Activity

  1. adityasharad commented on Nov 2, 2021

    @adityasharad
    Collaborator

    Thanks for the report! At a brief glance I agree this looks like a false positive. The code you link to implements operator= using a templated move_assign function, which appears to return *this in all code paths, but the analysis used by this particular query has not taken that fact into account.

    I have passed your suggestion on to the CodeQL C/C++ analysis team. Our current focus is on improving our security analysis. Because your report does not relate to a security query, we will put this on our backlog and prioritize it if we get enough reports of the same underlying issue in other projects. (If you think that your report is related to our security analysis, please clarify that in a comment.) We'll let you know here as soon as it's fixed.

    In the meantime, GitHub Code Scanning and lgtm.com have facilities for suppressing individual alerts or disabling a query: please feel free to use those features as appropriate in your codebase, particularly if these alerts are proving noisy.

  2. oknenavin commented on Nov 2, 2021

    @oknenavin
    Author

    Thanks a lot for the quick response! Well, gaps in code analysis are always a security risk, no? ;)
    Thanks again - I'll check how to suppress these gracefully as I don't want to cheat the system. :)

  3. added 2 commits that reference this issue on Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C++acknowledgedGitHub staff acknowledges this issuefalse-positivenot securityThis issue does not relate to a security query

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions