Skip to content

Commit ac43da8

Browse files
committed
MemSet() must not cast its pointer argument to int32* until after it has
checked that the pointer is actually word-aligned. Casting a non-aligned pointer to int32* is technically illegal per the C spec, and some recent versions of gcc actually generate bad code for the memset() when given such a pointer. Per report from Andrew Morrow.
1 parent d0f312e commit ac43da8

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/include/c.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
15-
* $PostgreSQL: pgsql/src/include/c.h,v 1.187 2005/07/02 17:01:52 momjian Exp $
15+
* $PostgreSQL: pgsql/src/include/c.h,v 1.188 2005/07/18 15:53:28 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -630,21 +630,22 @@ typedef NameData *Name;
630630
#define MemSet(start, val, len) \
631631
do \
632632
{ \
633-
int32 *_start = (int32 *) (start); \
633+
void *_vstart = (void *) (start); \
634634
int _val = (val); \
635635
Size _len = (len); \
636636
\
637-
if ((((long) _start) & INT_ALIGN_MASK) == 0 && \
637+
if ((((long) _vstart) & INT_ALIGN_MASK) == 0 && \
638638
(_len & INT_ALIGN_MASK) == 0 && \
639639
_val == 0 && \
640640
_len <= MEMSET_LOOP_LIMIT) \
641641
{ \
642+
int32 *_start = (int32 *) _vstart; \
642643
int32 *_stop = (int32 *) ((char *) _start + _len); \
643644
while (_start < _stop) \
644645
*_start++ = 0; \
645646
} \
646647
else \
647-
memset(_start, _val, _len); \
648+
memset(_vstart, _val, _len); \
648649
} while (0)
649650

650651
#define MEMSET_LOOP_LIMIT 1024

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy