@@ -59,8 +59,7 @@ int8in(char *str)
59
59
60
60
/*
61
61
* 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.
64
63
*/
65
64
while (* ptr && isspace (* ptr ))/* skip leading spaces */
66
65
ptr ++ ;
@@ -69,11 +68,17 @@ int8in(char *str)
69
68
else if (* ptr == '+' )
70
69
ptr ++ ;
71
70
if (!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 );
73
72
while (* 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
+ }
75
80
if (* ptr )/* trailing junk? */
76
- elog (ERROR ,"Bad int8 external representation'%s' " ,str );
81
+ elog (ERROR ,"Bad int8 external representation\"%s\" " ,str );
77
82
78
83
* result = (sign < 0 ) ?- tmp :tmp ;
79
84