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

Commit1a2b203

Browse files
committed
Fix NUMERIC field access macros to treat NaNs consistently.
Commit1453435 arranged to store numericNaN values as short-header numerics, but the field access macros did notget the memo: they thought only "SHORT" numerics have short headers.Most of the time this makes no difference because we don't access theweight or dscale of a NaN; but numeric_send does that. As pointed outby Andrew Gierth, this led to fetching uninitialized bytes.AFAICS this could not have any worse consequences than that; in particular,an unaligned stored numeric would have been detoasted by PG_GETARG_NUMERIC,so that there's no risk of a fetch off the end of memory. Still, the codeis wrong on its own terms, and it's not hard to foresee future changes thatmight expose us to real risks. So back-patch to all affected branches.
1 parent4b2a254 commit1a2b203

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

‎src/backend/utils/adt/numeric.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,10 @@ struct NumericData
169169
* otherwise, we want the long one. Instead of testing against each value, we
170170
* can just look at the high bit, for a slight efficiency gain.
171171
*/
172+
#defineNUMERIC_HEADER_IS_SHORT(n)(((n)->choice.n_header & 0x8000) != 0)
172173
#defineNUMERIC_HEADER_SIZE(n) \
173174
(VARHDRSZ + sizeof(uint16) + \
174-
(((NUMERIC_FLAGBITS(n)& 0x8000) == 0) ? sizeof(int16) : 0))
175+
(NUMERIC_HEADER_IS_SHORT(n)? 0 : sizeof(int16)))
175176

176177
/*
177178
* Short format definitions.
@@ -197,11 +198,11 @@ struct NumericData
197198
(NUMERIC_IS_SHORT(n) ? \
198199
(((n)->choice.n_short.n_header & NUMERIC_SHORT_SIGN_MASK) ? \
199200
NUMERIC_NEG : NUMERIC_POS) : NUMERIC_FLAGBITS(n))
200-
#defineNUMERIC_DSCALE(n)(NUMERIC_IS_SHORT((n)) ? \
201+
#defineNUMERIC_DSCALE(n)(NUMERIC_HEADER_IS_SHORT((n)) ? \
201202
((n)->choice.n_short.n_header & NUMERIC_SHORT_DSCALE_MASK) \
202203
>> NUMERIC_SHORT_DSCALE_SHIFT \
203204
: ((n)->choice.n_long.n_sign_dscale & NUMERIC_DSCALE_MASK))
204-
#defineNUMERIC_WEIGHT(n)(NUMERIC_IS_SHORT((n)) ? \
205+
#defineNUMERIC_WEIGHT(n)(NUMERIC_HEADER_IS_SHORT((n)) ? \
205206
(((n)->choice.n_short.n_header & NUMERIC_SHORT_WEIGHT_SIGN_MASK ? \
206207
~NUMERIC_SHORT_WEIGHT_MASK : 0) \
207208
| ((n)->choice.n_short.n_header & NUMERIC_SHORT_WEIGHT_MASK)) \
@@ -374,7 +375,7 @@ static void dump_var(const char *str, NumericVar *var);
374375

375376
#defineinit_var(v)MemSetAligned(v, 0, sizeof(NumericVar))
376377

377-
#defineNUMERIC_DIGITS(num) (NUMERIC_IS_SHORT(num) ? \
378+
#defineNUMERIC_DIGITS(num) (NUMERIC_HEADER_IS_SHORT(num) ? \
378379
(num)->choice.n_short.n_data : (num)->choice.n_long.n_data)
379380
#defineNUMERIC_NDIGITS(num) \
380381
((VARSIZE(num) - NUMERIC_HEADER_SIZE(num)) / sizeof(NumericDigit))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp