From: Tom Lane Date: Mon, 18 Jul 2005 15:54:11 +0000 (+0000) Subject: MemSet() must not cast its pointer argument to int32* until after it has X-Git-Url: http://waps.l3s.uni-hannover.de/gitweb/?a=commitdiff_plain;h=93bc5069dee0b846e2a7f316fe2b859ab97e60f9;p=users%2Fbernd%2Fpostgres.git 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. --- diff --git a/src/include/c.h b/src/include/c.h index 96ec68cc26..7d2219cd50 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -606,21 +606,22 @@ typedef NameData *Name; #define MemSet(start, val, len) \ do \ { \ - int32 * _start = (int32 *) (start); \ + void *_vstart = (void *) (start); \ int _val = (val); \ Size _len = (len); \ \ - if ((((long) _start) & INT_ALIGN_MASK) == 0 && \ + if ((((long) _vstart) & INT_ALIGN_MASK) == 0 && \ (_len & INT_ALIGN_MASK) == 0 && \ _val == 0 && \ _len <= MEMSET_LOOP_LIMIT) \ { \ - int32 * _stop = (int32 *) ((char *) _start + _len); \ + int32 *_start = (int32 *) _vstart; \ + int32 *_stop = (int32 *) ((char *) _start + _len); \ while (_start < _stop) \ *_start++ = 0; \ } \ else \ - memset((char *) _start, _val, _len); \ + memset(_vstart, _val, _len); \ } while (0) #define MEMSET_LOOP_LIMIT 1024