@@ -1003,9 +1003,6 @@ is_an_int(const char *str)
1003
1003
/*
1004
1004
* strtoint64 -- convert a string to 64-bit integer
1005
1005
*
1006
- * This function is a slightly modified version of pg_strtoint64() from
1007
- * src/backend/utils/adt/numutils.c.
1008
- *
1009
1006
* The function returns whether the conversion worked, and if so
1010
1007
* "*result" is set to the result.
1011
1008
*
@@ -1014,71 +1011,24 @@ is_an_int(const char *str)
1014
1011
bool
1015
1012
strtoint64 (const char * str , bool errorOK , int64 * result )
1016
1013
{
1017
- const char * ptr = str ;
1018
- int64 tmp = 0 ;
1019
- bool neg = false;
1020
-
1021
- /*
1022
- * Do our own scan, rather than relying on sscanf which might be broken
1023
- * for long long.
1024
- *
1025
- * As INT64_MIN can't be stored as a positive 64 bit integer, accumulate
1026
- * value as a negative number.
1027
- */
1014
+ char * end ;
1028
1015
1029
- /* skip leading spaces */
1030
- while (* ptr && isspace ((unsigned char ) * ptr ))
1031
- ptr ++ ;
1016
+ errno = 0 ;
1017
+ * result = strtoi64 (str , & end , 10 );
1032
1018
1033
- /* handle sign */
1034
- if (* ptr == '-' )
1019
+ if (errno == ERANGE )
1035
1020
{
1036
- ptr ++ ;
1037
- neg = true;
1038
- }
1039
- else if (* ptr == '+' )
1040
- ptr ++ ;
1041
-
1042
- /* require at least one digit */
1043
- if (unlikely (!isdigit ((unsigned char ) * ptr )))
1044
- goto invalid_syntax ;
1045
-
1046
- /* process digits */
1047
- while (* ptr && isdigit ((unsigned char ) * ptr ))
1048
- {
1049
- int8 digit = (* ptr ++ - '0' );
1050
-
1051
- if (unlikely (pg_mul_s64_overflow (tmp , 10 , & tmp )) ||
1052
- unlikely (pg_sub_s64_overflow (tmp , digit , & tmp )))
1053
- goto out_of_range ;
1021
+ if (!errorOK )
1022
+ pg_log_error ("value \"%s\" is out of range for type bigint" , str );
1023
+ return false;
1054
1024
}
1055
-
1056
- /* allow trailing whitespace, but not other trailing chars */
1057
- while (* ptr != '\0' && isspace ((unsigned char ) * ptr ))
1058
- ptr ++ ;
1059
-
1060
- if (unlikely (* ptr != '\0' ))
1061
- goto invalid_syntax ;
1062
-
1063
- if (!neg )
1025
+ if (str == end || * end != '\0' )
1064
1026
{
1065
- if (unlikely ( tmp == PG_INT64_MIN ) )
1066
- goto out_of_range ;
1067
- tmp = - tmp ;
1027
+ if (! errorOK )
1028
+ pg_log_error ( "invalid input syntax for type bigint: \"%s\"" , str ) ;
1029
+ return false ;
1068
1030
}
1069
-
1070
- * result = tmp ;
1071
1031
return true;
1072
-
1073
- out_of_range :
1074
- if (!errorOK )
1075
- pg_log_error ("value \"%s\" is out of range for type bigint" , str );
1076
- return false;
1077
-
1078
- invalid_syntax :
1079
- if (!errorOK )
1080
- pg_log_error ("invalid input syntax for type bigint: \"%s\"" , str );
1081
- return false;
1082
1032
}
1083
1033
1084
1034
/* convert string to double, detecting overflows/underflows */
0 commit comments