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

Appearance settings

Commit 6cf86f4

Browse filesBrowse files
committed
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>
1 parent 377b5ac commit 6cf86f4
Copy full SHA for 6cf86f4

File tree

Expand file treeCollapse file tree

7 files changed

+17
-27
lines changed
Filter options
Expand file treeCollapse file tree

7 files changed

+17
-27
lines changed

‎src/backend/nodes/outfuncs.c

Copy file name to clipboardExpand all lines: src/backend/nodes/outfuncs.c
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3235,7 +3235,7 @@ _outValue(StringInfo str, const Value *value)
32353235
switch (value->type)
32363236
{
32373237
case T_Integer:
3238-
appendStringInfo(str, "%ld", value->val.ival);
3238+
appendStringInfo(str, "%d", value->val.ival);
32393239
break;
32403240
case T_Float:
32413241

‎src/backend/nodes/read.c

Copy file name to clipboardExpand all lines: src/backend/nodes/read.c
+5-9Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,9 @@ nodeTokenType(char *token, int length)
224224

225225
errno = 0;
226226
val = strtol(token, &endptr, 10);
227-
(void) val; /* avoid compiler warning if unused */
228-
if (endptr != token + length || errno == ERANGE
229-
#ifdef HAVE_LONG_INT_64
230-
/* if long > 32 bits, check for overflow of int4 */
231-
|| val != (long) ((int32) val)
232-
#endif
233-
)
227+
if (endptr != token + length || errno == ERANGE ||
228+
/* check for overflow of int */
229+
val != (int) val)
234230
return T_Float;
235231
return T_Integer;
236232
}
@@ -387,9 +383,9 @@ nodeRead(char *token, int tok_len)
387383
case T_Integer:
388384

389385
/*
390-
* we know that the token terminates on a char atol will stop at
386+
* we know that the token terminates on a char atoi will stop at
391387
*/
392-
result = (Node *) makeInteger(atol(token));
388+
result = (Node *) makeInteger(atoi(token));
393389
break;
394390
case T_Float:
395391
{

‎src/backend/nodes/value.c

Copy file name to clipboardExpand all lines: src/backend/nodes/value.c
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* makeInteger
2121
*/
2222
Value *
23-
makeInteger(long i)
23+
makeInteger(int i)
2424
{
2525
Value *v = makeNode(Value);
2626

‎src/backend/parser/scan.l

Copy file name to clipboardExpand all lines: src/backend/parser/scan.l
+3-6Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,12 +1216,9 @@ process_integer_literal(const char *token, YYSTYPE *lval)
12161216

12171217
errno = 0;
12181218
val = strtol(token, &endptr, 10);
1219-
if (*endptr != '\0' || errno == ERANGE
1220-
#ifdef HAVE_LONG_INT_64
1221-
/* if long > 32 bits, check for overflow of int4 */
1222-
|| val != (long) ((int32) val)
1223-
#endif
1224-
)
1219+
if (*endptr != '\0' || errno == ERANGE ||
1220+
/* check for overflow of int */
1221+
val != (int) val)
12251222
{
12261223
/* integer too large, treat it as a float */
12271224
lval->str = pstrdup(token);

‎src/backend/utils/misc/guc.c

Copy file name to clipboardExpand all lines: src/backend/utils/misc/guc.c
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6913,7 +6913,7 @@ flatten_set_variable_args(const char *name, List *args)
69136913
switch (nodeTag(&con->val))
69146914
{
69156915
case T_Integer:
6916-
appendStringInfo(&buf, "%ld", intVal(&con->val));
6916+
appendStringInfo(&buf, "%d", intVal(&con->val));
69176917
break;
69186918
case T_Float:
69196919
/* represented as a string, so just copy it */

‎src/include/nodes/value.h

Copy file name to clipboardExpand all lines: src/include/nodes/value.h
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
* better to use the more general representation.)
3535
*
3636
* Note that an integer-looking string will get lexed as T_Float if
37-
* the value is too large to fit in a 'long'.
37+
* the value is too large to fit in an 'int'.
3838
*
3939
* Nulls, of course, don't need the value part at all.
4040
*----------------------
@@ -44,7 +44,7 @@ typedef struct Value
4444
NodeTag type; /* tag appropriately (eg. T_String) */
4545
union ValUnion
4646
{
47-
long ival; /* machine integer */
47+
int ival; /* machine integer */
4848
char *str; /* string */
4949
} val;
5050
} Value;
@@ -53,7 +53,7 @@ typedef struct Value
5353
#define floatVal(v) atof(((Value *)(v))->val.str)
5454
#define strVal(v) (((Value *)(v))->val.str)
5555

56-
extern Value *makeInteger(long i);
56+
extern Value *makeInteger(int i);
5757
extern Value *makeFloat(char *numericStr);
5858
extern Value *makeString(char *str);
5959
extern Value *makeBitString(char *str);

‎src/interfaces/ecpg/preproc/pgc.l

Copy file name to clipboardExpand all lines: src/interfaces/ecpg/preproc/pgc.l
+3-6Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -732,12 +732,9 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
732732

733733
errno = 0;
734734
val = strtol((char *)yytext, &endptr,10);
735-
if (*endptr != '\0' || errno == ERANGE
736-
#ifdef HAVE_LONG_INT_64
737-
/* if long > 32 bits, check for overflow of int4 */
738-
|| val != (long) ((int32) val)
739-
#endif
740-
)
735+
if (*endptr != '\0' || errno == ERANGE ||
736+
/* check for overflow of int */
737+
val != (int) val)
741738
{
742739
errno = 0;
743740
base_yylval.str = mm_strdup(yytext);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.