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)
7171if (s == NULL )
7272return (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 */
8077len = strlen (s );
8178atttypmod = len + VARHDRSZ ;
8279}
8380else
8481len = atttypmod - VARHDRSZ ;
8582
86- if (len > MaxAttrSize )
87- elog (ERROR ,"bpcharin: length of char() must be less than %ld" ,
88- MaxAttrSize );
89-
9083result = (char * )palloc (atttypmod );
9184VARSIZE (result )= atttypmod ;
9285r = VARDATA (result );
@@ -149,15 +142,12 @@ bpchar(char *s, int32 len)
149142if (s == NULL )
150143return (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 ))
153147return s ;
154148
155149rlen = 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
162152printf ("bpchar- convert string length %d (%d) ->%d (%d)\n" ,
163153VARSIZE (s )- VARHDRSZ ,VARSIZE (s ),rlen ,len );
@@ -333,13 +323,9 @@ varcharin(char *s, int dummy, int32 atttypmod)
333323return (char * )NULL ;
334324
335325len = strlen (s )+ VARHDRSZ ;
336- if (atttypmod != -1 && len > atttypmod )
326+ if (atttypmod >= ( int32 ) VARHDRSZ && len > atttypmod )
337327len = 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-
343329result = (char * )palloc (len );
344330VARSIZE (result )= len ;
345331strncpy (VARDATA (result ),s ,len - VARHDRSZ );
@@ -391,7 +377,7 @@ varchar(char *s, int32 slen)
391377return (char * )NULL ;
392378
393379len = VARSIZE (s );
394- if (( slen == -1 ) || ( len <=slen ) )
380+ if (slen < ( int32 ) VARHDRSZ || len <=slen )
395381return (char * )s ;
396382
397383/* only reach here if we need to truncate string... */
@@ -408,10 +394,6 @@ varchar(char *s, int32 slen)
408394len = slen - VARHDRSZ ;
409395#endif
410396
411- if (len > MaxAttrSize )
412- elog (ERROR ,"varchar: length of varchar() must be less than %ld" ,
413- MaxAttrSize );
414-
415397result = (char * )palloc (slen );
416398VARSIZE (result )= slen ;
417399strncpy (VARDATA (result ),VARDATA (s ),len );