mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-10-01 22:11:21 +02:00
Remove unnecessary limitations on lengths of bpchar and varchar constants.
Since we detect oversize tuples elsewhere, I see no reason not to allow string constants that are 'too long' --- after all, they might never get stored in a tuple at all.
This commit is contained in:
parent
a84c95634e
commit
57cf09591b
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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 $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -71,22 +71,15 @@ bpcharin(char *s, int dummy, int32 atttypmod)
|
|||||||
if (s == NULL)
|
if (s == NULL)
|
||||||
return (char *) NULL;
|
return (char *) NULL;
|
||||||
|
|
||||||
if (atttypmod == -1)
|
if (atttypmod < (int32) VARHDRSZ)
|
||||||
{
|
{
|
||||||
|
/* If typmod is -1 (or invalid), use the actual string length */
|
||||||
/*
|
|
||||||
* this is here because some functions can't supply the atttypmod
|
|
||||||
*/
|
|
||||||
len = strlen(s);
|
len = strlen(s);
|
||||||
atttypmod = len + VARHDRSZ;
|
atttypmod = len + VARHDRSZ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
len = atttypmod - VARHDRSZ;
|
len = atttypmod - VARHDRSZ;
|
||||||
|
|
||||||
if (len > MaxAttrSize)
|
|
||||||
elog(ERROR, "bpcharin: length of char() must be less than %ld",
|
|
||||||
MaxAttrSize);
|
|
||||||
|
|
||||||
result = (char *) palloc(atttypmod);
|
result = (char *) palloc(atttypmod);
|
||||||
VARSIZE(result) = atttypmod;
|
VARSIZE(result) = atttypmod;
|
||||||
r = VARDATA(result);
|
r = VARDATA(result);
|
||||||
@ -149,15 +142,12 @@ bpchar(char *s, int32 len)
|
|||||||
if (s == NULL)
|
if (s == NULL)
|
||||||
return (char *) 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;
|
return s;
|
||||||
|
|
||||||
rlen = len - VARHDRSZ;
|
rlen = len - VARHDRSZ;
|
||||||
|
|
||||||
if (rlen > MaxAttrSize)
|
|
||||||
elog(ERROR, "bpchar: length of char() must be less than %ld",
|
|
||||||
MaxAttrSize);
|
|
||||||
|
|
||||||
#ifdef STRINGDEBUG
|
#ifdef STRINGDEBUG
|
||||||
printf("bpchar- convert string length %d (%d) ->%d (%d)\n",
|
printf("bpchar- convert string length %d (%d) ->%d (%d)\n",
|
||||||
VARSIZE(s) - VARHDRSZ, VARSIZE(s), rlen, len);
|
VARSIZE(s) - VARHDRSZ, VARSIZE(s), rlen, len);
|
||||||
@ -333,13 +323,9 @@ varcharin(char *s, int dummy, int32 atttypmod)
|
|||||||
return (char *) NULL;
|
return (char *) NULL;
|
||||||
|
|
||||||
len = strlen(s) + VARHDRSZ;
|
len = strlen(s) + VARHDRSZ;
|
||||||
if (atttypmod != -1 && len > atttypmod)
|
if (atttypmod >= (int32) VARHDRSZ && len > atttypmod)
|
||||||
len = atttypmod; /* clip the string at max length */
|
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);
|
result = (char *) palloc(len);
|
||||||
VARSIZE(result) = len;
|
VARSIZE(result) = len;
|
||||||
strncpy(VARDATA(result), s, len - VARHDRSZ);
|
strncpy(VARDATA(result), s, len - VARHDRSZ);
|
||||||
@ -391,7 +377,7 @@ varchar(char *s, int32 slen)
|
|||||||
return (char *) NULL;
|
return (char *) NULL;
|
||||||
|
|
||||||
len = VARSIZE(s);
|
len = VARSIZE(s);
|
||||||
if ((slen == -1) || (len <= slen))
|
if (slen < (int32) VARHDRSZ || len <= slen)
|
||||||
return (char *) s;
|
return (char *) s;
|
||||||
|
|
||||||
/* only reach here if we need to truncate string... */
|
/* only reach here if we need to truncate string... */
|
||||||
@ -408,10 +394,6 @@ varchar(char *s, int32 slen)
|
|||||||
len = slen - VARHDRSZ;
|
len = slen - VARHDRSZ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (len > MaxAttrSize)
|
|
||||||
elog(ERROR, "varchar: length of varchar() must be less than %ld",
|
|
||||||
MaxAttrSize);
|
|
||||||
|
|
||||||
result = (char *) palloc(slen);
|
result = (char *) palloc(slen);
|
||||||
VARSIZE(result) = slen;
|
VARSIZE(result) = slen;
|
||||||
strncpy(VARDATA(result), VARDATA(s), len);
|
strncpy(VARDATA(result), VARDATA(s), len);
|
||||||
|
Loading…
Reference in New Issue
Block a user