*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.58 2000/01/26 05:57:14 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.59 2000/03/13 01:54:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
if (s == NULL)
return (char *) NULL;
- if (atttypmod == -1)
+ if (atttypmod < (int32) VARHDRSZ)
{
-
- /*
- * this is here because some functions can't supply the atttypmod
- */
+ /* If typmod is -1 (or invalid), use the actual string length */
len = strlen(s);
atttypmod = len + VARHDRSZ;
}
else
len = atttypmod - VARHDRSZ;
- if (len > MaxAttrSize)
- elog(ERROR, "bpcharin: length of char() must be less than %ld",
- MaxAttrSize);
-
result = (char *) palloc(atttypmod);
VARSIZE(result) = atttypmod;
r = VARDATA(result);
if (s == NULL)
return (char *) NULL;
- if ((len == -1) || (len == VARSIZE(s)))
+ /* No work if typmod is invalid or supplied data matches it already */
+ if (len < (int32) VARHDRSZ || len == VARSIZE(s))
return s;
rlen = len - VARHDRSZ;
- if (rlen > MaxAttrSize)
- elog(ERROR, "bpchar: length of char() must be less than %ld",
- MaxAttrSize);
-
#ifdef STRINGDEBUG
printf("bpchar- convert string length %d (%d) ->%d (%d)\n",
VARSIZE(s) - VARHDRSZ, VARSIZE(s), rlen, len);
return (char *) NULL;
len = strlen(s) + VARHDRSZ;
- if (atttypmod != -1 && len > atttypmod)
+ if (atttypmod >= (int32) VARHDRSZ && len > atttypmod)
len = atttypmod; /* clip the string at max length */
- if (len > MaxAttrSize)
- elog(ERROR, "varcharin: length of char() must be less than %ld",
- MaxAttrSize);
-
result = (char *) palloc(len);
VARSIZE(result) = len;
strncpy(VARDATA(result), s, len - VARHDRSZ);
return (char *) NULL;
len = VARSIZE(s);
- if ((slen == -1) || (len <= slen))
+ if (slen < (int32) VARHDRSZ || len <= slen)
return (char *) s;
/* only reach here if we need to truncate string... */
len = slen - VARHDRSZ;
#endif
- if (len > MaxAttrSize)
- elog(ERROR, "varchar: length of varchar() must be less than %ld",
- MaxAttrSize);
-
result = (char *) palloc(slen);
VARSIZE(result) = slen;
strncpy(VARDATA(result), VARDATA(s), len);