Hi.
Trying to implement some simple digest routines via UDFs and for whatever
reason I get: ERROR:  invalid memory alloc request size 4294967293 on
PG_RETURN_TEXT_P(); any ideas what the issue is exactly?
The code is verified as working when pulled out of a UDF and put into a
normal C program. Thanks.
dp_blag=# CREATE OR REPLACE FUNCTION sha512(text) RETURNS text AS
'dp_sha512.so','dp_sha512' LANGUAGE C STRICT;
CREATE FUNCTION
dp_blag=# SELECT sha512('jf');
ERROR:  invalid memory alloc request size 4294967293
PG_FUNCTION_INFO_V1(dp_sha512);
Datum
dp_sha512(PG_FUNCTION_ARGS)
{
        text *          hash;
        text *          plain;
        int32           hlen;
        plain = (text *)PG_GETARG_TEXT_P(0);
        if (NULL == plain) {
                ereport(ERROR,
            (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
            errmsg("invalid argument to function"))
        );
                PG_RETURN_NULL();
        }
        hlen = SHA512_DIGEST_LENGTH;
        hash = (text *)palloc(hlen+1);
        if (NULL == hash) {
                ereport(ERROR,
            (errcode(ERRCODE_INTERNAL_ERROR),
            errmsg("palloc() failed"))
        );
                PG_RETURN_NULL();
        }
        memset(VARDATA(hash), 0, hlen);
        SHA512(VARDATA(plain), hlen, VARDATA(hash));
        PG_RETURN_TEXT_P(hash);
}