Avoid undefined behavior with msvc compiler (src/include/port/pg_bitutils.h)

From: Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>
To: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Avoid undefined behavior with msvc compiler (src/include/port/pg_bitutils.h)
Date: 2023-07-29 12:37:19
Message-ID: CAEudQAoDhUZyKGJ1vbMGcgVUOcsixe-=jcVaDWarqkUg163D2w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

The pg_leftmost_one_pos32 function with msvc compiler,
relies on Assert to guarantee the correct result.

But msvc documentation [1] says clearly that
undefined behavior can occur.

Fix by checking the result of the function to avoid
a possible undefined behavior.

patch attached.

best regards,
Ranier Vilela

[1]
https://learn.microsoft.com/en-us/cpp/intrinsics/bitscanreverse-bitscanreverse64?view=msvc-170

Attachment Content-Type Size
0001-Avoid-undefined-behavior-with-msvc-compiler.patch application/octet-stream 1.9 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tomas Vondra 2023-07-29 12:38:07 Re: logical decoding and replication of sequences, take 2
Previous Message Tomas Vondra 2023-07-29 12:23:29 Re: logical decoding and replication of sequences, take 2