Skip to content

Commit a55a75f

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 84e5ce7 commit a55a75f

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/include/c.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
15-
* $Id: c.h,v 1.114 2002/01/22 19:02:39 tgl Exp $
15+
* $Id: c.h,v 1.114.2.1 2005/07/18 15:55:01 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -560,21 +560,22 @@ typedef NameData *Name;
560560
#define MemSet(start, val, len) \
561561
do \
562562
{ \
563-
int32 * _start = (int32 *) (start); \
563+
void *_vstart = (void *) (start); \
564564
int _val = (val); \
565565
Size _len = (len); \
566566
\
567-
if ((((long) _start) & INT_ALIGN_MASK) == 0 && \
567+
if ((((long) _vstart) & INT_ALIGN_MASK) == 0 && \
568568
(_len & INT_ALIGN_MASK) == 0 && \
569569
_val == 0 && \
570570
_len <= MEMSET_LOOP_LIMIT) \
571571
{ \
572-
int32 * _stop = (int32 *) ((char *) _start + _len); \
572+
int32 *_start = (int32 *) _vstart; \
573+
int32 *_stop = (int32 *) ((char *) _start + _len); \
573574
while (_start < _stop) \
574575
*_start++ = 0; \
575576
} \
576577
else \
577-
memset((char *) _start, _val, _len); \
578+
memset(_vstart, _val, _len); \
578579
} while (0)
579580

580581
#define MEMSET_LOOP_LIMIT 64

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