Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 57cf095

Browse files
committed
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.
1 parent a84c956 commit 57cf095

File tree

1 file changed

+7
-25
lines changed

1 file changed

+7
-25
lines changed

src/backend/utils/adt/varchar.c

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.58 2000/01/26 05:57:14 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.59 2000/03/13 01:54:07 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -71,22 +71,15 @@ bpcharin(char *s, int dummy, int32 atttypmod)
7171
if (s == NULL)
7272
return (char *) NULL;
7373

74-
if (atttypmod == -1)
74+
if (atttypmod < (int32) VARHDRSZ)
7575
{
76-
77-
/*
78-
* this is here because some functions can't supply the atttypmod
79-
*/
76+
/* If typmod is -1 (or invalid), use the actual string length */
8077
len = strlen(s);
8178
atttypmod = len + VARHDRSZ;
8279
}
8380
else
8481
len = atttypmod - VARHDRSZ;
8582

86-
if (len > MaxAttrSize)
87-
elog(ERROR, "bpcharin: length of char() must be less than %ld",
88-
MaxAttrSize);
89-
9083
result = (char *) palloc(atttypmod);
9184
VARSIZE(result) = atttypmod;
9285
r = VARDATA(result);
@@ -149,15 +142,12 @@ bpchar(char *s, int32 len)
149142
if (s == NULL)
150143
return (char *) NULL;
151144

152-
if ((len == -1) || (len == VARSIZE(s)))
145+
/* No work if typmod is invalid or supplied data matches it already */
146+
if (len < (int32) VARHDRSZ || len == VARSIZE(s))
153147
return s;
154148

155149
rlen = len - VARHDRSZ;
156150

157-
if (rlen > MaxAttrSize)
158-
elog(ERROR, "bpchar: length of char() must be less than %ld",
159-
MaxAttrSize);
160-
161151
#ifdef STRINGDEBUG
162152
printf("bpchar- convert string length %d (%d) ->%d (%d)\n",
163153
VARSIZE(s) - VARHDRSZ, VARSIZE(s), rlen, len);
@@ -333,13 +323,9 @@ varcharin(char *s, int dummy, int32 atttypmod)
333323
return (char *) NULL;
334324

335325
len = strlen(s) + VARHDRSZ;
336-
if (atttypmod != -1 && len > atttypmod)
326+
if (atttypmod >= (int32) VARHDRSZ && len > atttypmod)
337327
len = atttypmod; /* clip the string at max length */
338328

339-
if (len > MaxAttrSize)
340-
elog(ERROR, "varcharin: length of char() must be less than %ld",
341-
MaxAttrSize);
342-
343329
result = (char *) palloc(len);
344330
VARSIZE(result) = len;
345331
strncpy(VARDATA(result), s, len - VARHDRSZ);
@@ -391,7 +377,7 @@ varchar(char *s, int32 slen)
391377
return (char *) NULL;
392378

393379
len = VARSIZE(s);
394-
if ((slen == -1) || (len <= slen))
380+
if (slen < (int32) VARHDRSZ || len <= slen)
395381
return (char *) s;
396382

397383
/* only reach here if we need to truncate string... */
@@ -408,10 +394,6 @@ varchar(char *s, int32 slen)
408394
len = slen - VARHDRSZ;
409395
#endif
410396

411-
if (len > MaxAttrSize)
412-
elog(ERROR, "varchar: length of varchar() must be less than %ld",
413-
MaxAttrSize);
414-
415397
result = (char *) palloc(slen);
416398
VARSIZE(result) = slen;
417399
strncpy(VARDATA(result), VARDATA(s), len);

0 commit comments

Comments
 (0)