Re: Avoid unecessary MemSet call (src/backend/utils/cache/relcache.c)
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Ranier Vilela <ranier.vf@gmail.com>
Cc: David Rowley <dgrowleyml@gmail.com>,
Pg Hackers <pgsql-hackers@postgresql.org>
Date: 2022-05-17T23:22:20Z
Lists: pgsql-hackers
Ranier Vilela <ranier.vf@gmail.com> writes: > I found, I believe, a serious problem of incorrect usage of the memset api. > Historically, people have relied on using memset or MemSet, using the > variable name as an argument for the sizeof. > While it works correctly, for arrays, when it comes to pointers to > structures, things go awry. You'll have to convince people that any of these places are in fact incorrect. Everyone who's used C for any length of time is well aware of the possibility of getting sizeof() wrong in this sort of context, and I think we've been careful about it. Also, as a stylistic matter I think it's best to write "memset(&x, 0, sizeof(x))" where we can. Replacing sizeof(x) with sizeof(some type name) has its own risks of error, and therefore is not automatically an improvement. regards, tom lane
Commits
-
Replace many MemSet calls with struct initialization
- 9fd45870c143 16.0 landed
-
Change some unnecessary MemSet calls
- 258f48f858b0 16.0 landed
-
Avoid unnecessary MemSet call
- 8cd61d288adf 16.0 landed