@@ -59,8 +59,7 @@ int8in(char *str)
5959
6060/*
6161 * Do our own scan, rather than relying on sscanf which might be
62- * broken for long long. NOTE: this will not detect int64 overflow...
63- * but sscanf doesn't either...
62+ * broken for long long.
6463 */
6564while (* ptr && isspace (* ptr ))/* skip leading spaces */
6665ptr ++ ;
@@ -69,11 +68,17 @@ int8in(char *str)
6968else if (* ptr == '+' )
7069ptr ++ ;
7170if (!isdigit (* ptr ))/* require at least one digit */
72- elog (ERROR ,"Bad int8 external representation'%s' " ,str );
71+ elog (ERROR ,"Bad int8 external representation\"%s\" " ,str );
7372while (* ptr && isdigit (* ptr ))/* process digits */
74- tmp = tmp * 10 + (* ptr ++ - '0' );
73+ {
74+ int64 newtmp = tmp * 10 + (* ptr ++ - '0' );
75+
76+ if ((newtmp /10 )!= tmp )/* overflow? */
77+ elog (ERROR ,"int8 value out of range: \"%s\"" ,str );
78+ tmp = newtmp ;
79+ }
7580if (* ptr )/* trailing junk? */
76- elog (ERROR ,"Bad int8 external representation'%s' " ,str );
81+ elog (ERROR ,"Bad int8 external representation\"%s\" " ,str );
7782
7883* result = (sign < 0 ) ?- tmp :tmp ;
7984