diff options
Diffstat (limited to 'src/backend/utils/adt/numeric.c')
-rw-r--r-- | src/backend/utils/adt/numeric.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c index ddc44d51791..48d95e90501 100644 --- a/src/backend/utils/adt/numeric.c +++ b/src/backend/utils/adt/numeric.c @@ -3143,7 +3143,12 @@ float8_numeric(PG_FUNCTION_ARGS) if (isnan(val)) PG_RETURN_NUMERIC(make_result(&const_nan)); - sprintf(buf, "%.*g", DBL_DIG, val); + if (isinf(val)) + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("cannot convert infinity to numeric"))); + + snprintf(buf, sizeof(buf), "%.*g", DBL_DIG, val); init_var(&result); @@ -3209,7 +3214,12 @@ float4_numeric(PG_FUNCTION_ARGS) if (isnan(val)) PG_RETURN_NUMERIC(make_result(&const_nan)); - sprintf(buf, "%.*g", FLT_DIG, val); + if (isinf(val)) + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("cannot convert infinity to numeric"))); + + snprintf(buf, sizeof(buf), "%.*g", FLT_DIG, val); init_var(&result); |