Thread: Re: ERROR: int8 conversion to int4 is out of range

Re: ERROR: int8 conversion to int4 is out of range

From
Colin Campbell
Date:
Hi,

Fixed it. (If anyone cares :-) Seems it might be a gcc optimizer
"feature".

The code in backend/utils/adt/int8.c was:

        if ((val < (int64)INT_MIN) || (val > (int64)INT_MAX))
                elog(ERROR, "int8 conversion to int4 is out of range");

If I changed it to

        if ((val < INT_MIN))
                elog(ERROR, "int8 conversion to int4 is out of range - too small");
        if ((val > INT_MAX))
                elog(ERROR, "int8 conversion to int4 is out of range - too big");

the error went away.

Colin


Re: ERROR: int8 conversion to int4 is out of range

From
Tom Lane
Date:
Colin Campbell <sgcccdc@citec.qld.gov.au> writes:
> Fixed it. (If anyone cares :-) Seems it might be a gcc optimizer
> "feature".

Which gcc version, on just what platform, was that again?

> The code in backend/utils/adt/int8.c was:

>         if ((val < (int64)INT_MIN) || (val > (int64)INT_MAX))
>                 elog(ERROR, "int8 conversion to int4 is out of range");

> If I changed it to

>         if ((val < INT_MIN))
>                 elog(ERROR, "int8 conversion to int4 is out of range - too small");
>         if ((val > INT_MAX))
>                 elog(ERROR, "int8 conversion to int4 is out of range - too big");

> the error went away.

Hmm, there seem to be two changes here.  Is it the splitup of the OR
test, or the removal of the (int64) casts that does the trick?  Or
do you really need both changes?

I wouldn't mind applying the OR splitup to the master sources, but I'm
a little more paranoid about applying the cast removal.  Seems like that
might induce problems on other compilers.  So I'm hoping you only need
the OR splitup to make it work.

            regards, tom lane