Use SHRT_MIN and SHRT_MAX for 2-byte integer limits.
This commit is contained in:
parent
e7946a53ad
commit
174f984b76
@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.9 1997/10/25 05:19:22 thomas Exp $
|
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.10 1997/11/17 16:24:17 thomas Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -30,11 +30,21 @@
|
|||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#ifdef HAVE_LIMITS
|
||||||
|
#include <limits.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "postgres.h"
|
#include "postgres.h"
|
||||||
#include "fmgr.h"
|
#include "fmgr.h"
|
||||||
#include "utils/builtins.h" /* where the declarations go */
|
#include "utils/builtins.h" /* where the declarations go */
|
||||||
|
|
||||||
|
#ifndef SHRT_MAX
|
||||||
|
#define SHRT_MAX (0x7FFF)
|
||||||
|
#endif
|
||||||
|
#ifndef SHRT_MIN
|
||||||
|
#define SHRT_MIN (-0x8000)
|
||||||
|
#endif
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* USER I/O ROUTINES *
|
* USER I/O ROUTINES *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
@ -221,10 +231,10 @@ i2toi4(int16 arg1)
|
|||||||
int16
|
int16
|
||||||
i4toi2(int32 arg1)
|
i4toi2(int32 arg1)
|
||||||
{
|
{
|
||||||
if (arg1 < -0x8000)
|
if (arg1 < SHRT_MIN)
|
||||||
elog(NOTICE, "i4toi2: \"%d\" causes int2 underflow", arg1);
|
elog(WARN, "i4toi2: '%d' causes int2 underflow", arg1);
|
||||||
if (arg1 > 0x7FFF)
|
if (arg1 > SHRT_MAX)
|
||||||
elog(NOTICE, "i4toi2: \"%d\" causes int2 overflow", arg1);
|
elog(WARN, "i4toi2: '%d' causes int2 overflow", arg1);
|
||||||
|
|
||||||
return ((int16) arg1);
|
return ((int16) arg1);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user