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

Commite07d4dd

Browse files
committed
Suppress compiler warning in relptr_store().
clang 13 with -Wextra warns that "performing pointer subtraction witha null pointer has undefined behavior" in the places where freepage.ctries to set a relptr variable to constant NULL. This appears to bea compiler bug, but it's unlikely to get fixed instantly. Fortunately,we can work around it by introducing an inline support function, whichseems like a good change anyway because it removes the macro's existingdouble-evaluation hazard.Backpatch to v10 where this code was introduced.Patch by me, based on an idea of Andres Freund's.Discussion:https://postgr.es/m/48826.1648310694@sss.pgh.pa.us
1 parent41b00f8 commite07d4dd

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

‎src/include/utils/relptr.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,32 @@
5656
#definerelptr_is_null(rp) \
5757
((rp).relptr_off == 0)
5858

59+
/* We use this inline to avoid double eval of "val" in relptr_store */
60+
staticinlineSize
61+
relptr_store_eval(char*base,char*val)
62+
{
63+
if (val==NULL)
64+
return0;
65+
else
66+
{
67+
Assert(val>base);
68+
returnval-base;
69+
}
70+
}
71+
5972
#ifdefHAVE__BUILTIN_TYPES_COMPATIBLE_P
6073
#definerelptr_store(base,rp,val) \
6174
(AssertVariableIsOfTypeMacro(base, char *), \
6275
AssertVariableIsOfTypeMacro(val, __typeof__((rp).relptr_type)), \
63-
(rp).relptr_off =((val) == NULL ? 0 : ((char *) (val)) - (base)))
76+
(rp).relptr_off =relptr_store_eval(base, (char *) (val)))
6477
#else
6578
/*
6679
* If we don't have __builtin_types_compatible_p, assume we might not have
6780
* __typeof__ either.
6881
*/
6982
#definerelptr_store(base,rp,val) \
7083
(AssertVariableIsOfTypeMacro(base, char *), \
71-
(rp).relptr_off =((val) == NULL ? 0 : ((char *) (val)) - (base)))
84+
(rp).relptr_off =relptr_store_eval(base, (char *) (val)))
7285
#endif
7386

7487
#definerelptr_copy(rp1,rp2) \

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp