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

Commit58666ed

Browse files
committed
Fix latent portability issue in pgwin32_dispatch_queued_signals().
The first iteration of the signal-checking loop would compute sigmask(0)which expands to 1<<(-1) which is undefined behavior according to theC standard. The lack of field reports of trouble suggest that itevaluates to 0 on all existing Windows compilers, but that's hardlysomething to rely on. Since signal 0 isn't a queueable signal anyway,we can just make the loop iterate from 1 instead, and save a few cyclesas well as avoiding the undefined behavior.In passing, avoid evaluating the volatile expression UNBLOCKED_SIGNAL_QUEUEtwice in a row; there's no reason to waste cycles like that.Noted by Aleksander Alekseev, though this isn't his proposed fix.Back-patch to all supported branches.
1 parenteb7308d commit58666ed

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

‎src/backend/port/win32/signal.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ HANDLEpgwin32_initial_signal_pipe = INVALID_HANDLE_VALUE;
3333
*/
3434
staticCRITICAL_SECTIONpg_signal_crit_sec;
3535

36+
/* Note that array elements 0 are unused since they correspond to signal 0 */
3637
staticpqsigfuncpg_signal_array[PG_SIGNAL_COUNT];
3738
staticpqsigfuncpg_signal_defaults[PG_SIGNAL_COUNT];
3839

@@ -105,15 +106,15 @@ pgwin32_signal_initialize(void)
105106
void
106107
pgwin32_dispatch_queued_signals(void)
107108
{
108-
inti;
109+
intexec_mask;
109110

110111
EnterCriticalSection(&pg_signal_crit_sec);
111-
while (UNBLOCKED_SIGNAL_QUEUE())
112+
while ((exec_mask=UNBLOCKED_SIGNAL_QUEUE())!=0)
112113
{
113114
/* One or more unblocked signals queued for execution */
114-
intexec_mask=UNBLOCKED_SIGNAL_QUEUE();
115+
inti;
115116

116-
for (i=0;i<PG_SIGNAL_COUNT;i++)
117+
for (i=1;i<PG_SIGNAL_COUNT;i++)
117118
{
118119
if (exec_mask&sigmask(i))
119120
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp