public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: David Malcolm <dmalcolm@redhat.com>
To: Tim Lange <mail@tim-lange.me>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH 1/2 v2] analyzer: consider that realloc could shrink the buffer [PR106539]
Date: Thu, 11 Aug 2022 15:25:57 -0400	[thread overview]
Message-ID: <3ed2bf522657f1f46a1a75be4e67b2ccdb45dd1c.camel@redhat.com> (raw)
In-Reply-To: <20220811172452.65996-1-mail@tim-lange.me>

On Thu, 2022-08-11 at 19:24 +0200, Tim Lange wrote:
> This patch adds the "shrinks buffer" case to the success_with_move
> modelling of realloc.

Thanks for the updated patch.

> 
> Regression-tested on Linux x86-64, further ran the analyzer tests
> with
> the -m32 option.

[...snip...]

> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/analyzer/realloc-5.c
> @@ -0,0 +1,45 @@
> +#include "analyzer-decls.h"
> +
> +typedef __SIZE_TYPE__ size_t;
> +
> +#define NULL ((void *)0)
> +
> +extern void *malloc (size_t __size)
> +  __attribute__ ((__nothrow__ , __leaf__))
> +  __attribute__ ((__malloc__))
> +  __attribute__ ((__alloc_size__ (1)));
> +extern void *realloc (void *__ptr, size_t __size)
> +  __attribute__ ((__nothrow__ , __leaf__))
> +  __attribute__ ((__warn_unused_result__))
> +  __attribute__ ((__alloc_size__ (2)));
> +extern void free (void *__ptr)
> +  __attribute__ ((__nothrow__ , __leaf__));
> +extern void *memset (void *__ptr, int __value, size_t __size);
> +
> +/* realloc where the region shrinks on success_with_move.  */
> +
> +void test_1 ()
> +{
> +  char *p = malloc (16);
> +  if (!p)
> +    return;
> +  memset (p, 1, 16);
> +
> +  char *q = realloc (p, 8);
> +  if (!q)
> +    {
> +      free (p);
> +      return;
> +    }
> +  else if (p != q)
> +    {
> +      __analyzer_dump_capacity (q); /* { dg-warning "capacity:
> '\\(\[^\n\r\]*\\)8'" } */
> +      __analyzer_eval (q[8] == 1); /* { dg-line eval } */
> +    
> +      /* { dg-warning "UNKNOWN" "warning" { target *-*-* } eval } */
> +      /* { dg-warning "overread" "warning" { target *-*-* } eval }
> */

Strictly speaking, this "overread" warning is dependent on the followup
patch, but assuming that that patch is OK, this patch is also OK.

Thanks
Dave

> +      /* { dg-warning "use of uninitialized value" "warning" {
> target *-*-* } eval } */
> +    }
> +
> +  free (q);
> +}



      parent reply	other threads:[~2022-08-11 19:26 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-09 21:19 [PATCH 1/2] " Tim Lange
2022-08-09 21:19 ` [PATCH 2/2] analyzer: out-of-bounds checker [PR106000] Tim Lange
2022-08-09 22:44   ` David Malcolm
2022-08-09 22:02 ` [PATCH 1/2] analyzer: consider that realloc could shrink the buffer [PR106539] David Malcolm
2022-08-11 17:24 ` [PATCH 1/2 v2] " Tim Lange
2022-08-11 17:24   ` [PATCH 2/2 v2] analyzer: out-of-bounds checker [PR106000] Tim Lange
2022-08-11 19:30     ` David Malcolm
2022-08-11 19:25   ` David Malcolm [this message]

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=3ed2bf522657f1f46a1a75be4e67b2ccdb45dd1c.camel@redhat.com \
    --to=dmalcolm@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=mail@tim-lange.me \
    /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: link
Be 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).