Skip to content

Commit 174f984

Browse files
author
Thomas G. Lockhart
committed
Use SHRT_MIN and SHRT_MAX for 2-byte integer limits.
1 parent e7946a5 commit 174f984

File tree

1 file changed

+15
-5
lines changed
  • src/backend/utils/adt

1 file changed

+15
-5
lines changed

src/backend/utils/adt/int.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.9 1997/10/25 05:19:22 thomas Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.10 1997/11/17 16:24:17 thomas Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -30,11 +30,21 @@
3030
*/
3131
#include <stdio.h>
3232
#include <string.h>
33+
#ifdef HAVE_LIMITS
34+
#include <limits.h>
35+
#endif
3336

3437
#include "postgres.h"
3538
#include "fmgr.h"
3639
#include "utils/builtins.h" /* where the declarations go */
3740

41+
#ifndef SHRT_MAX
42+
#define SHRT_MAX (0x7FFF)
43+
#endif
44+
#ifndef SHRT_MIN
45+
#define SHRT_MIN (-0x8000)
46+
#endif
47+
3848
/*****************************************************************************
3949
* USER I/O ROUTINES *
4050
*****************************************************************************/
@@ -221,10 +231,10 @@ i2toi4(int16 arg1)
221231
int16
222232
i4toi2(int32 arg1)
223233
{
224-
if (arg1 < -0x8000)
225-
elog(NOTICE, "i4toi2: \"%d\" causes int2 underflow", arg1);
226-
if (arg1 > 0x7FFF)
227-
elog(NOTICE, "i4toi2: \"%d\" causes int2 overflow", arg1);
234+
if (arg1 < SHRT_MIN)
235+
elog(WARN, "i4toi2: '%d' causes int2 underflow", arg1);
236+
if (arg1 > SHRT_MAX)
237+
elog(WARN, "i4toi2: '%d' causes int2 overflow", arg1);
228238

229239
return ((int16) arg1);
230240
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy