public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "dmalcolm at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug analyzer/107851] New: Issues with -Wanalyzer-allocation-size messages Date: Wed, 23 Nov 2022 21:53:34 +0000 [thread overview] Message-ID: <bug-107851-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107851 Bug ID: 107851 Summary: Issues with -Wanalyzer-allocation-size messages Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: analyzer Assignee: dmalcolm at gcc dot gnu.org Reporter: dmalcolm at gcc dot gnu.org Target Milestone: --- Taken from gcc.dg/analyzer/allocation-size-2.c #include <stdlib.h> #include <stdint.h> void test_2 (int32_t n) { int32_t *ptr = malloc (n * sizeof (int16_t)); free (ptr); } With "-fanalyzer" (https://godbolt.org/z/fKcdrrh3z) we get: <source>: In function 'test_2': <source>:6:18: warning: allocated buffer size is not a multiple of the pointee's size [CWE-131] [-Wanalyzer-allocation-size] 6 | int32_t *ptr = malloc (n * sizeof (int16_t)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 'test_2': event 1 | | 6 | int32_t *ptr = malloc (n * sizeof (int16_t)); | | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (1) allocated '(long unsigned int)n * 2' bytes and assigned to 'int32_t *' {aka 'int *'} here; 'sizeof (int32_t {aka int})' is '4' | <source>:6:18: warning: allocated buffer size is not a multiple of the pointee's size [CWE-131] [-Wanalyzer-allocation-size] 'test_2': events 1-3 | | 6 | int32_t *ptr = malloc (n * sizeof (int16_t)); | | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (1) allocated '(long unsigned int)n * 2' bytes here | | (2) allocated '(long unsigned int)n * 2' bytes here | | (3) assigned to 'int32_t *' {aka 'int *'} here; 'sizeof (int32_t {aka int})' is '4' | Compiler returned: 0 With "-fanalyzer -fanalyzer-fine-grained" ( https://godbolt.org/z/3fbvofPje ) we get: <source>: In function 'test_2': <source>:6:18: warning: allocated buffer size is not a multiple of the pointee's size [CWE-131] [-Wanalyzer-allocation-size] 6 | int32_t *ptr = malloc (n * sizeof (int16_t)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 'test_2': events 1-3 | | 6 | int32_t *ptr = malloc (n * sizeof (int16_t)); | | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (1) allocated '(long unsigned int)n * 2' bytes here | | (2) allocated '(long unsigned int)n * 2' bytes here | | (3) assigned to 'int32_t *' {aka 'int *'} here; 'sizeof (int32_t {aka int})' is '4' | Compiler returned: 0 Issues: * note how the "allocated '(long unsigned int)n * 2' bytes here" message is repeated * note how we get a duplicate diagnostic, which goes away with -fanalyzer-fine-grained
next reply other threads:[~2022-11-23 21:53 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-11-23 21:53 dmalcolm at gcc dot gnu.org [this message] 2022-12-02 21:32 ` [Bug analyzer/107851] " cvs-commit at gcc dot gnu.org 2022-12-02 22:05 ` dmalcolm at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-107851-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).