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

2023-07-31 Thread John Naylor
On Mon, Jul 31, 2023 at 5:57 PM Tom Lane wrote: > > John Naylor writes: > > Works for me, so done that way for both forward and reverse variants. Since > > the return value is no longer checked in any builds, I thought about > > removing the variable containing it, but it seems best to leave it

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

2023-07-31 Thread Tom Lane
John Naylor writes: > On Sun, Jul 30, 2023 at 9:45 PM Tom Lane wrote: >> That's basically equivalent to the existing Assert(non_zero). >> I think it'd be okay to drop that one and instead have >> the same Assert condition as other platforms, but having both >> would be redundant. > Works for me,

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

2023-07-31 Thread John Naylor
On Sun, Jul 30, 2023 at 9:45 PM Tom Lane wrote: > > John Naylor writes: > > It seems that we should have "Assert(word != 0);" at the top, which matches > > the other platforms anyway, so I'll add that. > > That's basically equivalent to the existing Assert(non_zero). > I think it'd be okay to dro

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

2023-07-30 Thread Tom Lane
John Naylor writes: > It seems that we should have "Assert(word != 0);" at the top, which matches > the other platforms anyway, so I'll add that. That's basically equivalent to the existing Assert(non_zero). I think it'd be okay to drop that one and instead have the same Assert condition as other

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

2023-07-30 Thread John Naylor
On Sat, Jul 29, 2023 at 7:37 PM Ranier Vilela wrote: > > 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. It seems that we should have "Assert(word !=

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

2023-07-29 Thread Ranier Vilela
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 regard