Skip to content

Commit 58666ed

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 the C standard. The lack of field reports of trouble suggest that it evaluates to 0 on all existing Windows compilers, but that's hardly something 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 cycles as well as avoiding the undefined behavior. In passing, avoid evaluating the volatile expression UNBLOCKED_SIGNAL_QUEUE twice 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 parent eb7308d commit 58666ed

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 @@ HANDLE pgwin32_initial_signal_pipe = INVALID_HANDLE_VALUE;
3333
*/
3434
static CRITICAL_SECTION pg_signal_crit_sec;
3535

36+
/* Note that array elements 0 are unused since they correspond to signal 0 */
3637
static pqsigfunc pg_signal_array[PG_SIGNAL_COUNT];
3738
static pqsigfunc pg_signal_defaults[PG_SIGNAL_COUNT];
3839

@@ -105,15 +106,15 @@ pgwin32_signal_initialize(void)
105106
void
106107
pgwin32_dispatch_queued_signals(void)
107108
{
108-
int i;
109+
int exec_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-
int exec_mask = UNBLOCKED_SIGNAL_QUEUE();
115+
int i;
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy