]> 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 df2165863d6c88ffc255f5f2350b18d7a541aa87..6e9fa45e37e37ff91c000e48d844d629b2b69f18 100644 (file)
@@ -4,12 +4,12 @@
  *       routines to convert a string (legal ascii representation of node) back
  *       to nodes
  *
- * Portions Copyright (c) 1996-2005, 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.46 2004/12/31 21:59:55 pgsql Exp $
+ *       src/backend/nodes/read.c
  *
  * HISTORY
  *       AUTHOR                        DATE                    MAJOR EVENT
@@ -41,10 +41,10 @@ stringToNode(char *str)
        void       *retval;
 
        /*
-        * We save and restore the pre-existing state of pg_strtok. This makes
-        * the world safe for re-entrant invocation of stringToNode, without
-        * incurring a lot of notational overhead by having to pass the
-        * next-character pointer around through all the readfuncs.c code.
+        * We save and restore the pre-existing state of pg_strtok. This makes the
+        * world safe for re-entrant invocation of stringToNode, without incurring
+        * a lot of notational overhead by having to pass the next-character
+        * pointer around through all the readfuncs.c code.
         */
        save_strtok = pg_strtok_ptr;
 
@@ -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.
  */
@@ -211,25 +211,22 @@ nodeTokenType(char *token, int length)
        if (*numptr == '+' || *numptr == '-')
                numptr++, numlen--;
        if ((numlen > 0 && isdigit((unsigned char) *numptr)) ||
-       (numlen > 1 && *numptr == '.' && isdigit((unsigned char) numptr[1])))
+               (numlen > 1 && *numptr == '.' && isdigit((unsigned char) numptr[1])))
        {
                /*
                 * Yes.  Figure out whether it is integral or float; this requires
-                * both a syntax check and a range check. strtol() can do both for
-                * us. We know the token will end at a character that strtol will
-                * stop at, so we do not need to modify the string.
+                * both a syntax check and a range check. strtol() can do both for us.
+                * We know the token will end at a character that strtol will stop at,
+                * so we do not need to modify the string.
                 */
                long            val;
                char       *endptr;
 
                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,10 +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:
                        {
@@ -409,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;