aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Eisentraut <peter_e@gmx.net>2018-03-12 12:17:58 -0400
committerPeter Eisentraut <peter_e@gmx.net>2018-03-13 09:56:25 -0400
commit6cf86f435472b27bbc5e22c713bca08aa2d94af7 (patch)
treec1722f6bb851bcb468a2d01edf23f872c0b89597 /src
parent377b5ac4845c5ffbf992ee95c32d7d16d38b9081 (diff)
downloadpostgresql-6cf86f435472b27bbc5e22c713bca08aa2d94af7.tar.gz
postgresql-6cf86f435472b27bbc5e22c713bca08aa2d94af7.zip
Change internal integer representation of Value node
A Value node would store an integer as a long. This causes needless portability risks, as long can be of varying sizes. Change it to use int instead. All code using this was already careful to only store 32-bit values anyway. Reviewed-by: Michael Paquier <michael@paquier.xyz>
Diffstat (limited to 'src')
-rw-r--r--src/backend/nodes/outfuncs.c2
-rw-r--r--src/backend/nodes/read.c14
-rw-r--r--src/backend/nodes/value.c2
-rw-r--r--src/backend/parser/scan.l9
-rw-r--r--src/backend/utils/misc/guc.c2
-rw-r--r--src/include/nodes/value.h6
-rw-r--r--src/interfaces/ecpg/preproc/pgc.l9
7 files changed, 17 insertions, 27 deletions
diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c
index 1785ea39186..fd808919548 100644
--- a/src/backend/nodes/outfuncs.c
+++ b/src/backend/nodes/outfuncs.c
@@ -3235,7 +3235,7 @@ _outValue(StringInfo str, const Value *value)
switch (value->type)
{
case T_Integer:
- appendStringInfo(str, "%ld", value->val.ival);
+ appendStringInfo(str, "%d", value->val.ival);
break;
case T_Float:
diff --git a/src/backend/nodes/read.c b/src/backend/nodes/read.c
index 76414029d83..6e9fa45e37e 100644
--- a/src/backend/nodes/read.c
+++ b/src/backend/nodes/read.c
@@ -224,13 +224,9 @@ nodeTokenType(char *token, int length)
errno = 0;
val = strtol(token, &endptr, 10);
- (void) val; /* avoid compiler warning if unused */
- if (endptr != token + length || errno == ERANGE
-#ifdef HAVE_LONG_INT_64
- /* if long > 32 bits, check for overflow of int4 */
- || val != (long) ((int32) val)
-#endif
- )
+ if (endptr != token + length || errno == ERANGE ||
+ /* check for overflow of int */
+ val != (int) val)
return T_Float;
return T_Integer;
}
@@ -387,9 +383,9 @@ nodeRead(char *token, int tok_len)
case T_Integer:
/*
- * we know that the token terminates on a char atol will stop at
+ * we know that the token terminates on a char atoi will stop at
*/
- result = (Node *) makeInteger(atol(token));
+ result = (Node *) makeInteger(atoi(token));
break;
case T_Float:
{
diff --git a/src/backend/nodes/value.c b/src/backend/nodes/value.c
index 8f0428fce12..2a30307baf4 100644
--- a/src/backend/nodes/value.c
+++ b/src/backend/nodes/value.c
@@ -20,7 +20,7 @@
* makeInteger
*/
Value *
-makeInteger(long i)
+makeInteger(int i)
{
Value *v = makeNode(Value);
diff --git a/src/backend/parser/scan.l b/src/backend/parser/scan.l
index eedef7c0052..97d4dee6282 100644
--- a/src/backend/parser/scan.l
+++ b/src/backend/parser/scan.l
@@ -1216,12 +1216,9 @@ process_integer_literal(const char *token, YYSTYPE *lval)
errno = 0;
val = strtol(token, &endptr, 10);
- if (*endptr != '\0' || errno == ERANGE
-#ifdef HAVE_LONG_INT_64
- /* if long > 32 bits, check for overflow of int4 */
- || val != (long) ((int32) val)
-#endif
- )
+ if (*endptr != '\0' || errno == ERANGE ||
+ /* check for overflow of int */
+ val != (int) val)
{
/* integer too large, treat it as a float */
lval->str = pstrdup(token);
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index a4f9b3668e0..fc3e10c7509 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -6913,7 +6913,7 @@ flatten_set_variable_args(const char *name, List *args)
switch (nodeTag(&con->val))
{
case T_Integer:
- appendStringInfo(&buf, "%ld", intVal(&con->val));
+ appendStringInfo(&buf, "%d", intVal(&con->val));
break;
case T_Float:
/* represented as a string, so just copy it */
diff --git a/src/include/nodes/value.h b/src/include/nodes/value.h
index 94d09e176ee..16657145153 100644
--- a/src/include/nodes/value.h
+++ b/src/include/nodes/value.h
@@ -34,7 +34,7 @@
* better to use the more general representation.)
*
* Note that an integer-looking string will get lexed as T_Float if
- * the value is too large to fit in a 'long'.
+ * the value is too large to fit in an 'int'.
*
* Nulls, of course, don't need the value part at all.
*----------------------
@@ -44,7 +44,7 @@ typedef struct Value
NodeTag type; /* tag appropriately (eg. T_String) */
union ValUnion
{
- long ival; /* machine integer */
+ int ival; /* machine integer */
char *str; /* string */
} val;
} Value;
@@ -53,7 +53,7 @@ typedef struct Value
#define floatVal(v) atof(((Value *)(v))->val.str)
#define strVal(v) (((Value *)(v))->val.str)
-extern Value *makeInteger(long i);
+extern Value *makeInteger(int i);
extern Value *makeFloat(char *numericStr);
extern Value *makeString(char *str);
extern Value *makeBitString(char *str);
diff --git a/src/interfaces/ecpg/preproc/pgc.l b/src/interfaces/ecpg/preproc/pgc.l
index e99b7ff5863..ba1798c77eb 100644
--- a/src/interfaces/ecpg/preproc/pgc.l
+++ b/src/interfaces/ecpg/preproc/pgc.l
@@ -732,12 +732,9 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
errno = 0;
val = strtol((char *)yytext, &endptr,10);
- if (*endptr != '\0' || errno == ERANGE
-#ifdef HAVE_LONG_INT_64
- /* if long > 32 bits, check for overflow of int4 */
- || val != (long) ((int32) val)
-#endif
- )
+ if (*endptr != '\0' || errno == ERANGE ||
+ /* check for overflow of int */
+ val != (int) val)
{
errno = 0;
base_yylval.str = mm_strdup(yytext);