Re: [HACKERS] [RFC] Fix div/mul crash and more undefined behavior

2012-11-19 Thread Andres Freund
On 2012-11-19 11:04:31 -0500, Tom Lane wrote: > Xi Wang writes: > > Since INTn_MIN and INTn_MAX are standard macros from the C library, > > can we assume that every C compiler should provide them in stdint.h? > > Not every C compiler provides stdint.h, unfortunately --- otherwise > I'd not be so r

Re: [HACKERS] [RFC] Fix div/mul crash and more undefined behavior

2012-11-19 Thread Tom Lane
Xi Wang writes: > The reality is that C compilers are not friendly to postcondition > checking; they consider signed integer overflow as undefined behavior, > so they do whatever they want to do. Even workaround options like > -fwrapv are often broken, not to mention that they may not even have >

Re: [HACKERS] [RFC] Fix div/mul crash and more undefined behavior

2012-11-19 Thread Xi Wang
On 11/19/12 11:04 AM, Tom Lane wrote: > I thought about this some more and realized that we can handle it > by realizing that division by -1 is the same as negation, and so > we can copy the method used in int4um. So the code would look like > > if (arg2 == -1) > { > res

Re: [HACKERS] [RFC] Fix div/mul crash and more undefined behavior

2012-11-19 Thread Tom Lane
Xi Wang writes: > On 11/18/12 6:47 PM, Tom Lane wrote: >> I was against this style of coding before, and I still am. >> For one thing, it's just about certain to introduce conflicts >> against system headers. > I totally agree. > I would be happy to rewrite the integer overflow checks without >

Re: [HACKERS] [RFC] Fix div/mul crash and more undefined behavior

2012-11-18 Thread Xi Wang
On 11/18/12 6:47 PM, Tom Lane wrote: > Xi Wang writes: >> [ patch adding a bunch of explicit INT_MIN/MAX constants ] > > I was against this style of coding before, and I still am. > For one thing, it's just about certain to introduce conflicts > against system headers. I totally agree. I would

Re: [HACKERS] [RFC] Fix div/mul crash and more undefined behavior

2012-11-18 Thread Tom Lane
Xi Wang writes: > [ patch adding a bunch of explicit INT_MIN/MAX constants ] I was against this style of coding before, and I still am. For one thing, it's just about certain to introduce conflicts against system headers. regards, tom lane -- Sent via pgsql-hackers mai