oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
/* total number of tuples to be returned */
- funcctx->max_calls = PG_GETARG_UINT32(0);
+ funcctx->max_calls = PG_GETARG_INT32(0);
/* Build a tuple descriptor for our result type */
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
Datum
chr (PG_FUNCTION_ARGS)
{
- uint32 cvalue = PG_GETARG_UINT32(0);
+ int32 arg = PG_GETARG_INT32(0);
+ uint32 cvalue;
text *result;
int encoding = GetDatabaseEncoding();
+ /*
+ * Error out on arguments that make no sense or that we can't validly
+ * represent in the encoding.
+ */
+ if (arg < 0)
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("character number must be positive")));
+ else if (arg == 0)
+ ereport(ERROR,
+ (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
+ errmsg("null character not permitted")));
+
+ cvalue = arg;
+
if (encoding == PG_UTF8 && cvalue > 127)
{
/* for Unicode we treat the argument as a code point */
if (cvalue > 0x0010ffff)
ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
- errmsg("requested character too large for encoding: %d",
+ errmsg("requested character too large for encoding: %u",
cvalue)));
if (cvalue > 0xffff)
if (!pg_utf8_islegal(wch, bytes))
ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
- errmsg("requested character not valid for encoding: %d",
+ errmsg("requested character not valid for encoding: %u",
cvalue)));
}
else
{
bool is_mb;
- /*
- * Error out on arguments that make no sense or that we can't validly
- * represent in the encoding.
- */
- if (cvalue == 0)
- ereport(ERROR,
- (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
- errmsg("null character not permitted")));
-
is_mb = pg_encoding_max_length(encoding) > 1;
if ((is_mb && (cvalue > 127)) || (!is_mb && (cvalue > 255)))
ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
- errmsg("requested character too large for encoding: %d",
+ errmsg("requested character too large for encoding: %u",
cvalue)));
result = (text *) palloc(VARHDRSZ + 1);