Re: [PATCH][BUG FIX] Uninitialized variable parsed

From: Mark Dilger <hornschnorter(at)gmail(dot)com>
To: Ranier Vilela <ranier_gyn(at)hotmail(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH][BUG FIX] Uninitialized variable parsed
Date: 2019-11-22 18:08:43
Message-ID: 82a48303-0d9c-e200-0867-143e365ab3f0@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message David Steele 2019-11-22 18:10:06 Re: backup manifests
Previous Message Peter Geoghegan 2019-11-22 17:37:08 Re: [PATCH][BUG FIX] Pointer var initilialized with boolean.