Improved error messages for halfvec input [skip ci]

This commit is contained in:
Andrew Kane
2024-04-03 22:20:13 -07:00
parent 7667abe9a0
commit 9f61dcff5d
2 changed files with 17 additions and 6 deletions

View File

@@ -435,6 +435,8 @@ halfvec_in(PG_FUNCTION_ARGS)
while (pt != NULL && *stringEnd != ']')
{
float val;
if (dim == HALFVEC_MAX_DIM)
ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
@@ -450,15 +452,24 @@ halfvec_in(PG_FUNCTION_ARGS)
errmsg("invalid input syntax for type halfvec: \"%s\"", lit)));
/* Use strtof like float4in to avoid a double-rounding problem */
x[dim] = Float4ToHalf(strtof(pt, &stringEnd));
CheckElement(x[dim]);
dim++;
errno = 0;
val = strtof(pt, &stringEnd);
if (stringEnd == pt)
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for type halfvec: \"%s\"", lit)));
x[dim] = Float4ToHalfUnchecked(val);
if ((errno == ERANGE && isinf(val)) || (HalfIsInf(x[dim]) && !isinf(val)) || (HalfIsZero(x[dim]) && val != 0))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("\"%s\" is out of range for type halfvec", pt)));
CheckElement(x[dim]);
dim++;
while (halfvec_isspace(*stringEnd))
stringEnd++;