public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/71219] Warn about  (struct S*)malloc(n) where n < sizeof(struct S)
       [not found] <bug-71219-4@http.gcc.gnu.org/bugzilla/>
@ 2020-11-10 17:31 ` redi at gcc dot gnu.org
  2023-09-19  5:11 ` muecker at gwdg dot de
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2020-11-10 17:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71219

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2016-05-26 00:00:00         |2020-11-10

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Complete testcase:

#include <stdlib.h>

struct S1 {
  unsigned int x;
  float        y;
  struct S1   *z;
};


struct S1 *f1(void) {
  struct S1 *p = malloc(sizeof(p));  // diagnostic required
  return p;
}


It would probably make sense to not only warn for malloc, but also for other
functions with __attribute__((malloc)) and __attribute__((alloc_size(n))) where
n!=sizeof(*p). That would also help for xmalloc and similar wrappers in gcc and
glibc.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/71219] Warn about  (struct S*)malloc(n) where n < sizeof(struct S)
       [not found] <bug-71219-4@http.gcc.gnu.org/bugzilla/>
  2020-11-10 17:31 ` [Bug c/71219] Warn about (struct S*)malloc(n) where n < sizeof(struct S) redi at gcc dot gnu.org
@ 2023-09-19  5:11 ` muecker at gwdg dot de
  2023-11-01 21:37 ` cvs-commit at gcc dot gnu.org
  2024-02-17  5:11 ` sjames at gcc dot gnu.org
  3 siblings, 0 replies; 4+ messages in thread
From: muecker at gwdg dot de @ 2023-09-19  5:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71219

Martin Uecker <muecker at gwdg dot de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |muecker at gwdg dot de

--- Comment #5 from Martin Uecker <muecker at gwdg dot de> ---
PATCH: https://gcc.gnu.org/pipermail/gcc-patches/2023-September/630817.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/71219] Warn about  (struct S*)malloc(n) where n < sizeof(struct S)
       [not found] <bug-71219-4@http.gcc.gnu.org/bugzilla/>
  2020-11-10 17:31 ` [Bug c/71219] Warn about (struct S*)malloc(n) where n < sizeof(struct S) redi at gcc dot gnu.org
  2023-09-19  5:11 ` muecker at gwdg dot de
@ 2023-11-01 21:37 ` cvs-commit at gcc dot gnu.org
  2024-02-17  5:11 ` sjames at gcc dot gnu.org
  3 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-11-01 21:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71219

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Martin Uecker <uecker@gcc.gnu.org>:

https://gcc.gnu.org/g:d880e093d92084f55b10626610ef059fd9194a6a

commit r14-5059-gd880e093d92084f55b10626610ef059fd9194a6a
Author: Martin Uecker <uecker@tugraz.at>
Date:   Thu Jul 27 13:36:05 2023 +0200

    c: Add Walloc-size to warn about insufficient size in allocations [PR71219]

    Add option Walloc-size that warns about allocations that have
    insufficient storage for the target type of the pointer the
    storage is assigned to. Added to Wextra.

            PR c/71219
    gcc:
            * doc/invoke.texi: Document -Walloc-size option.

    gcc/c-family:

            * c.opt (Walloc-size): New option.

    gcc/c:
            * c-typeck.cc (convert_for_assignment): Add warning.

    gcc/testsuite:

            * gcc.dg/Walloc-size-1.c: New test.
            * gcc.dg/Walloc-size-2.c: New test.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/71219] Warn about  (struct S*)malloc(n) where n < sizeof(struct S)
       [not found] <bug-71219-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2023-11-01 21:37 ` cvs-commit at gcc dot gnu.org
@ 2024-02-17  5:11 ` sjames at gcc dot gnu.org
  3 siblings, 0 replies; 4+ messages in thread
From: sjames at gcc dot gnu.org @ 2024-02-17  5:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71219

Sam James <sjames at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
   Target Milestone|---                         |14.0
         Resolution|---                         |FIXED

--- Comment #7 from Sam James <sjames at gcc dot gnu.org> ---
Fixed for 14?

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-02-17  5:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-71219-4@http.gcc.gnu.org/bugzilla/>
2020-11-10 17:31 ` [Bug c/71219] Warn about (struct S*)malloc(n) where n < sizeof(struct S) redi at gcc dot gnu.org
2023-09-19  5:11 ` muecker at gwdg dot de
2023-11-01 21:37 ` cvs-commit at gcc dot gnu.org
2024-02-17  5:11 ` sjames at gcc dot gnu.org

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).