Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit709170b

Browse files
committed
Consistently use unsigned arithmetic for alignment calculations.
This avoids an assumption about the signed number representation. It isanticipated to have no functional changes on supported configurations;many two's complement assumptions remain elsewhere.Per a suggestion from Andres Freund.
1 parent713a9f2 commit709170b

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

‎src/backend/access/hash/hashfunc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ hash_any(register const unsigned char *k, register int keylen)
314314
a=b=c=0x9e3779b9+len+3923095;
315315

316316
/* If the source pointer is word-aligned, we use word-wide fetches */
317-
if (((intptr_t)k&UINT32_ALIGN_MASK)==0)
317+
if (((uintptr_t)k&UINT32_ALIGN_MASK)==0)
318318
{
319319
/* Code path for aligned source data */
320320
registerconstuint32*ka= (constuint32*)k;

‎src/include/access/tupmacs.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
#defineatt_align_datum(cur_offset,attalign,attlen,attdatum) \
102102
( \
103103
((attlen) == -1 && VARATT_IS_SHORT(DatumGetPointer(attdatum))) ? \
104-
(intptr_t) (cur_offset) : \
104+
(uintptr_t) (cur_offset) : \
105105
att_align_nominal(cur_offset, attalign) \
106106
)
107107

@@ -116,13 +116,13 @@
116116
* aligned 4-byte length word; in either case we need not align.)
117117
*
118118
* Note: some callers pass a "char *" pointer for cur_offset. This is
119-
* a bit of a hack but should work all right as long asintptr_t is the
119+
* a bit of a hack but should work all right as long asuintptr_t is the
120120
* correct width.
121121
*/
122122
#defineatt_align_pointer(cur_offset,attalign,attlen,attptr) \
123123
( \
124124
((attlen) == -1 && VARATT_NOT_PAD_BYTE(attptr)) ? \
125-
(intptr_t) (cur_offset) : \
125+
(uintptr_t) (cur_offset) : \
126126
att_align_nominal(cur_offset, attalign) \
127127
)
128128

@@ -144,7 +144,7 @@
144144
#defineatt_align_nominal(cur_offset,attalign) \
145145
( \
146146
((attalign) == 'i') ? INTALIGN(cur_offset) : \
147-
(((attalign) == 'c') ? (intptr_t) (cur_offset) : \
147+
(((attalign) == 'c') ? (uintptr_t) (cur_offset) : \
148148
(((attalign) == 'd') ? DOUBLEALIGN(cur_offset) : \
149149
( \
150150
AssertMacro((attalign) == 's'), \

‎src/include/c.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ typedef NameData *Name;
486486
*True iff pointer is properly aligned to point to the given type.
487487
*/
488488
#definePointerIsAligned(pointer,type) \
489-
(((intptr_t)(pointer) % (sizeof (type))) == 0)
489+
(((uintptr_t)(pointer) % (sizeof (type))) == 0)
490490

491491
#defineOidIsValid(objectId) ((bool) ((objectId) != InvalidOid))
492492

@@ -532,7 +532,7 @@ typedef NameData *Name;
532532
*/
533533

534534
#defineTYPEALIGN(ALIGNVAL,LEN) \
535-
(((intptr_t) (LEN) + ((ALIGNVAL) - 1)) & ~((intptr_t) ((ALIGNVAL) - 1)))
535+
(((uintptr_t) (LEN) + ((ALIGNVAL) - 1)) & ~((uintptr_t) ((ALIGNVAL) - 1)))
536536

537537
#defineSHORTALIGN(LEN)TYPEALIGN(ALIGNOF_SHORT, (LEN))
538538
#defineINTALIGN(LEN)TYPEALIGN(ALIGNOF_INT, (LEN))
@@ -543,7 +543,7 @@ typedef NameData *Name;
543543
#defineBUFFERALIGN(LEN)TYPEALIGN(ALIGNOF_BUFFER, (LEN))
544544

545545
#defineTYPEALIGN_DOWN(ALIGNVAL,LEN) \
546-
(((intptr_t) (LEN)) & ~((intptr_t) ((ALIGNVAL) - 1)))
546+
(((uintptr_t) (LEN)) & ~((uintptr_t) ((ALIGNVAL) - 1)))
547547

548548
#defineSHORTALIGN_DOWN(LEN)TYPEALIGN_DOWN(ALIGNOF_SHORT, (LEN))
549549
#defineINTALIGN_DOWN(LEN)TYPEALIGN_DOWN(ALIGNOF_INT, (LEN))
@@ -552,7 +552,7 @@ typedef NameData *Name;
552552
#defineMAXALIGN_DOWN(LEN)TYPEALIGN_DOWN(MAXIMUM_ALIGNOF, (LEN))
553553

554554
/*
555-
* The above macros will not work with types wider thanintptr_t, like with
555+
* The above macros will not work with types wider thanuintptr_t, like with
556556
* uint64 on 32-bit platforms. That's not problem for the usual use where a
557557
* pointer or a length is aligned, but for the odd case that you need to
558558
* align something (potentially) wider, use TYPEALIGN64.
@@ -763,7 +763,7 @@ typedef NameData *Name;
763763
int_val= (val); \
764764
Size_len= (len); \
765765
\
766-
if ((((intptr_t)_vstart)&LONG_ALIGN_MASK)==0&& \
766+
if ((((uintptr_t)_vstart)&LONG_ALIGN_MASK)==0&& \
767767
(_len&LONG_ALIGN_MASK)==0&& \
768768
_val==0&& \
769769
_len <=MEMSET_LOOP_LIMIT&& \

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp