Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2fa3302

Browse files
author
Thomas G. Lockhart
committed
Use limits.h for INT, SHRT, and SCHAR min and max values rather than
hardcoded values.
1 parent174f984 commit2fa3302

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

‎src/backend/utils/adt/numutils.c

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/numutils.c,v 1.16 1997/09/18 20:22:15 momjian Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/numutils.c,v 1.17 1997/11/17 16:26:27 thomas Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
1717
#include<stdio.h>/* for sprintf() */
1818
#include<errno.h>
1919
#include<math.h>
20+
#ifdefHAVE_LIMITS
21+
#include<limits.h>
22+
#endif
2023
#include"postgres.h"
2124
#include"utils/builtins.h"/* where the declarations go */
2225
#ifndefHAVE_MEMMOVE
@@ -26,6 +29,25 @@
2629
#endif
2730
#include<port-protos.h>/* ecvt(), fcvt() */
2831

32+
#ifndefINT_MAX
33+
#defineINT_MAX (0x7FFFFFFFL)
34+
#endif
35+
#ifndefINT_MIN
36+
#defineINT_MIN (-0x80000000L)
37+
#endif
38+
#ifndefSHRT_MAX
39+
#defineSHRT_MAX (0x7FFF)
40+
#endif
41+
#ifndefSHRT_MIN
42+
#defineSHRT_MIN (-0x8000)
43+
#endif
44+
#ifndefSCHAR_MAX
45+
#defineSCHAR_MAX (0x7F)
46+
#endif
47+
#ifndefSCHAR_MIN
48+
#defineSCHAR_MIN (-0x80)
49+
#endif
50+
2951
int32
3052
pg_atoi(char*s,intsize,intc)
3153
{
@@ -46,37 +68,37 @@ pg_atoi(char *s, int size, int c)
4668
casesizeof(int32):
4769
#ifdefHAS_LONG_LONG
4870
/* won't get ERANGE on these with 64-bit longs... */
49-
if (l<-0x80000000L)
71+
if (l<INT_MIN)
5072
{
5173
errno=ERANGE;
5274
elog(WARN,"pg_atoi: error reading \"%s\": %m",s);
5375
}
54-
if (l>0x7fffffffL)
76+
if (l>INT_MAX)
5577
{
5678
errno=ERANGE;
5779
elog(WARN,"pg_atoi: error reading \"%s\": %m",s);
5880
}
5981
#endif/* HAS_LONG_LONG */
6082
break;
6183
casesizeof(int16):
62-
if (l<-0x8000)
84+
if (l<SHRT_MIN)
6385
{
6486
errno=ERANGE;
6587
elog(WARN,"pg_atoi: error reading \"%s\": %m",s);
6688
}
67-
if (l>0x7fff)
89+
if (l>SHRT_MAX)
6890
{
6991
errno=ERANGE;
7092
elog(WARN,"pg_atoi: error reading \"%s\": %m",s);
7193
}
7294
break;
7395
casesizeof(int8):
74-
if (l<-0x80)
96+
if (l<SCHAR_MIN)
7597
{
7698
errno=ERANGE;
7799
elog(WARN,"pg_atoi: error reading \"%s\": %m",s);
78100
}
79-
if (l>0x7f)
101+
if (l>SCHAR_MAX)
80102
{
81103
errno=ERANGE;
82104
elog(WARN,"pg_atoi: error reading \"%s\": %m",s);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp