]> granicus.if.org Git - postgresql/blobdiff - src/backend/nodes/read.c
Change internal integer representation of Value node
[postgresql] / src / backend / nodes / read.c
index 14ccb88942ce1975ae750dcd425609fa7bedf08a..6e9fa45e37e37ff91c000e48d844d629b2b69f18 100644 (file)
@@ -4,12 +4,12 @@
  *       routines to convert a string (legal ascii representation of node) back
  *       to nodes
  *
- * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/nodes/read.c,v 1.48 2006/03/05 15:58:28 momjian Exp $
+ *       src/backend/nodes/read.c
  *
  * HISTORY
  *       AUTHOR                        DATE                    MAJOR EVENT
@@ -85,21 +85,21 @@ stringToNode(char *str)
  *       Backslashes themselves must also be backslashed for consistency.
  *       Any other character can be, but need not be, backslashed as well.
  *     * If the resulting token is '<>' (with no backslash), it is returned
- *       as a non-NULL pointer to the token but with length == 0.      Note that
+ *       as a non-NULL pointer to the token but with length == 0.  Note that
  *       there is no other way to get a zero-length token.
  *
  * Returns a pointer to the start of the next token, and the length of the
- * token (including any embedded backslashes!) in *length.     If there are
+ * token (including any embedded backslashes!) in *length.  If there are
  * no more tokens, NULL and 0 are returned.
  *
  * NOTE: this routine doesn't remove backslashes; the caller must do so
  * if necessary (see "debackslash").
  *
  * NOTE: prior to release 7.0, this routine also had a special case to treat
- * a token starting with '"' as extending to the next '"'.     This code was
+ * a token starting with '"' as extending to the next '"'.  This code was
  * broken, however, since it would fail to cope with a string containing an
  * embedded '"'.  I have therefore removed this special case, and instead
- * introduced rules for using backslashes to quote characters. Higher-level
+ * introduced rules for using backslashes to quote characters.  Higher-level
  * code should add backslashes to a string constant to ensure it is treated
  * as a single token.
  */
@@ -224,12 +224,9 @@ nodeTokenType(char *token, int length)
 
                errno = 0;
                val = strtol(token, &endptr, 10);
-               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;
        }
@@ -244,7 +241,7 @@ nodeTokenType(char *token, int length)
                retval = RIGHT_PAREN;
        else if (*token == '{')
                retval = LEFT_BRACE;
-       else if (*token == '\"' && length > 1 && token[length - 1] == '\"')
+       else if (*token == '"' && length > 1 && token[length - 1] == '"')
                retval = T_String;
        else if (*token == 'b')
                retval = T_BitString;
@@ -258,7 +255,7 @@ nodeTokenType(char *token, int length)
  *       Slightly higher-level reader.
  *
  * This routine applies some semantic knowledge on top of the purely
- * lexical tokenizer pg_strtok().      It can read
+ * lexical tokenizer pg_strtok().   It can read
  *     * Value token nodes (integers, floats, or strings);
  *     * General nodes (via parseNodeString() from readfuncs.c);
  *     * Lists of the above;
@@ -289,7 +286,7 @@ nodeRead(char *token, int tok_len)
 
        type = nodeTokenType(token, tok_len);
 
-       switch (type)
+       switch ((int) type)
        {
                case LEFT_BRACE:
                        result = parseNodeString();
@@ -386,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:
                        {
@@ -408,7 +405,7 @@ nodeRead(char *token, int tok_len)
                                char       *val = palloc(tok_len);
 
                                /* skip leading 'b' */
-                               strncpy(val, token + 1, tok_len - 1);
+                               memcpy(val, token + 1, tok_len - 1);
                                val[tok_len - 1] = '\0';
                                result = (Node *) makeBitString(val);
                                break;