8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.97 2004/03/04 21:47:18 neilc Exp $
11
+ * $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.98 2004/03/11 02:11:13 neilc Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -185,41 +185,55 @@ float4in(PG_FUNCTION_ARGS)
185
185
186
186
errno = 0 ;
187
187
val = strtod (num , & endptr );
188
- if (* endptr != '\0' )
188
+
189
+ if (errno == ERANGE )
190
+ ereport (ERROR ,
191
+ (errcode (ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE ),
192
+ errmsg ("\"%s\" is out of range for type real" , num )));
193
+
194
+ if (num == endptr )
189
195
{
190
196
/*
191
- * XXX we should accept "Infinity" and "-Infinity" too, but what
192
- * are the correct values to assign? HUGE_VAL will provoke an
193
- * error from CheckFloat4Val.
197
+ * We didn't find anything that looks like a float in the input
198
+ *
199
+ * In releases prior to 7.5, we accepted an empty string as
200
+ * valid input (yielding a float8 of 0). In 7.5, we accept
201
+ * empty strings, but emit a warning noting that the feature
202
+ * is deprecated. In 7.6+, the warning should be replaced by
203
+ * an error.
204
+ *
205
+ * XXX we should accept "Infinity" and "-Infinity" too, but
206
+ * what are the correct values to assign? HUGE_VAL will
207
+ * provoke an error from CheckFloat4Val.
194
208
*/
195
- if (strcasecmp (num , "NaN" ) == 0 )
209
+ if (* num == '\0' )
210
+ {
211
+ ereport (WARNING ,
212
+ (errcode (ERRCODE_WARNING_DEPRECATED_FEATURE ),
213
+ errmsg ("deprecated input syntax for type real: \"\"" ),
214
+ errdetail ("This input will be rejected in "
215
+ "a future release of PostgreSQL." )));
216
+ Assert (val == 0.0 );
217
+ }
218
+ else if (strcasecmp (num , "NaN" ) == 0 )
196
219
val = NAN ;
197
220
else
198
221
ereport (ERROR ,
199
222
(errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
200
223
errmsg ("invalid input syntax for type real: \"%s\"" ,
201
224
num )));
202
225
}
203
- else
204
- {
205
- if (errno == ERANGE )
206
- ereport (ERROR ,
207
- (errcode (ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE ),
208
- errmsg ("\"%s\" is out of range for type real" , num )));
209
- }
210
226
211
- /*
212
- * In releases prior to 7.5, we accepted an empty string as valid
213
- * input (yielding a float4 of 0). In 7.5, we accept empty
214
- * strings, but emit a warning noting that the feature is
215
- * deprecated. In 7.6+, the warning should be replaced by an error.
216
- */
217
- if (num == endptr )
218
- ereport (WARNING ,
219
- (errcode (ERRCODE_WARNING_DEPRECATED_FEATURE ),
220
- errmsg ("deprecated input syntax for type real: \"\"" ),
221
- errdetail ("This input will be rejected in "
222
- "a future release of PostgreSQL." )));
227
+ /* skip trailing whitespace */
228
+ while (* endptr != '\0' && isspace (* endptr ))
229
+ endptr ++ ;
230
+
231
+ /* if there is any junk left at the end of the string, bail out */
232
+ if (* endptr != '\0' )
233
+ ereport (ERROR ,
234
+ (errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
235
+ errmsg ("invalid input syntax for type real: \"%s\"" ,
236
+ num )));
223
237
224
238
/*
225
239
* if we get here, we have a legal double, still need to check to see
@@ -300,9 +314,33 @@ float8in(PG_FUNCTION_ARGS)
300
314
301
315
errno = 0 ;
302
316
val = strtod (num , & endptr );
303
- if (* endptr != '\0' )
317
+
318
+ if (errno == ERANGE )
319
+ ereport (ERROR ,
320
+ (errcode (ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE ),
321
+ errmsg ("\"%s\" is out of range for type double precision" , num )));
322
+
323
+ if (num == endptr )
304
324
{
305
- if (strcasecmp (num , "NaN" ) == 0 )
325
+ /*
326
+ * We didn't find anything that looks like a float in the input
327
+ *
328
+ * In releases prior to 7.5, we accepted an empty string as
329
+ * valid input (yielding a float8 of 0). In 7.5, we accept
330
+ * empty strings, but emit a warning noting that the feature
331
+ * is deprecated. In 7.6+, the warning should be replaced by
332
+ * an error.
333
+ */
334
+ if (* num == '\0' )
335
+ {
336
+ ereport (WARNING ,
337
+ (errcode (ERRCODE_WARNING_DEPRECATED_FEATURE ),
338
+ errmsg ("deprecated input syntax for type double precision: \"\"" ),
339
+ errdetail ("This input will be rejected in "
340
+ "a future release of PostgreSQL." )));
341
+ Assert (val == 0.0 );
342
+ }
343
+ else if (strcasecmp (num , "NaN" ) == 0 )
306
344
val = NAN ;
307
345
else if (strcasecmp (num , "Infinity" ) == 0 )
308
346
val = HUGE_VAL ;
@@ -314,26 +352,17 @@ float8in(PG_FUNCTION_ARGS)
314
352
errmsg ("invalid input syntax for type double precision: \"%s\"" ,
315
353
num )));
316
354
}
317
- else
318
- {
319
- if (errno == ERANGE )
320
- ereport (ERROR ,
321
- (errcode (ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE ),
322
- errmsg ("\"%s\" is out of range for type double precision" , num )));
323
- }
324
355
325
- /*
326
- * In releases prior to 7.5, we accepted an empty string as valid
327
- * input (yielding a float8 of 0). In 7.5, we accept empty
328
- * strings, but emit a warning noting that the feature is
329
- * deprecated. In 7.6+, the warning should be replaced by an error.
330
- */
331
- if (num == endptr )
332
- ereport (WARNING ,
333
- (errcode (ERRCODE_WARNING_DEPRECATED_FEATURE ),
334
- errmsg ("deprecated input syntax for type double precision: \"\"" ),
335
- errdetail ("This input will be rejected in "
336
- "a future release of PostgreSQL." )));
356
+ /* skip trailing whitespace */
357
+ while (* endptr != '\0' && isspace (* endptr ))
358
+ endptr ++ ;
359
+
360
+ /* if there is any junk left at the end of the string, bail out */
361
+ if (* endptr != '\0' )
362
+ ereport (ERROR ,
363
+ (errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
364
+ errmsg ("invalid input syntax for type double precision: \"%s\"" ,
365
+ num )));
337
366
338
367
CheckFloat8Val (val );
339
368
0 commit comments