Re: [PATCH][BUG FIX] Uninitialized variable parsed - Mailing list pgsql-hackers

From Mark Dilger
Subject Re: [PATCH][BUG FIX] Uninitialized variable parsed
Date
Msg-id 82a48303-0d9c-e200-0867-143e365ab3f0@gmail.com
Whole thread Raw
In response to [PATCH][BUG FIX] Uninitialized variable parsed  (Ranier Vilela <ranier_gyn@hotmail.com>)
List pgsql-hackers

On 11/22/19 8:50 AM, Ranier Vilela wrote:
> Hi,
> Typo mystake?
> Memset only fill a pointer size, not the size of struct.

Hello Ranier,

I think you may be misunderstanding how sizeof(*parsed)
works in the attached code.  Try compiling and running:

     #include <stdio.h>

     typedef struct mystruct {
         long long a[512];
     } mystruct;

     int main (void)
     {
         mystruct *myptr;
         printf("sizeof *myptr = %u\n", sizeof(*myptr));
         printf("sizeof mystruct * = %u\n", sizeof(mystruct *));
         return 0;
     }

On my hardware, I get:

$ ./a.out
sizeof *myptr = 4096
sizeof mystruct * = 8

Which I think demonstrates that sizeof(*myptr) works just as
well as sizeof(mystruct) would work.  It is also better style
since, if somebody changes the type of myptr, the sizeof()
does not need to be adjusted in kind.


> Best regards.
> Ranier Vilela
> 
> --- \dll\postgresql-12.0\a\backend\access\rmgrdesc\xactdesc.c    Mon Sep 30 17:06:55 2019
> +++ xactdesc.c    Fri Nov 22 13:40:13 2019
> @@ -35,7 +35,7 @@
>   {
>       char       *data = ((char *) xlrec) + MinSizeOfXactCommit;
>   
> -    memset(parsed, 0, sizeof(*parsed));
> +    memset(parsed, 0, sizeof(xl_xact_parsed_commit));
>   
>       parsed->xinfo = 0;            /* default, if no XLOG_XACT_HAS_INFO is
>                                    * present */
> @@ -130,7 +130,7 @@
>   {
>       char       *data = ((char *) xlrec) + MinSizeOfXactAbort;
>   
> -    memset(parsed, 0, sizeof(*parsed));
> +    memset(parsed, 0, sizeof(xl_xact_parsed_commit));
>   
>       parsed->xinfo = 0;            /* default, if no XLOG_XACT_HAS_INFO is
>                                    * present */
> 

-- 
Mark Dilger



pgsql-hackers by date:

Previous
From: Peter Geoghegan
Date:
Subject: Re: [PATCH][BUG FIX] Pointer var initilialized with boolean.
Next
From: David Steele
Date:
Subject: Re: backup manifests