8
8
*
9
9
*
10
10
* 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 $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -71,22 +71,15 @@ bpcharin(char *s, int dummy, int32 atttypmod)
71
71
if (s == NULL )
72
72
return (char * ) NULL ;
73
73
74
- if (atttypmod == -1 )
74
+ if (atttypmod < ( int32 ) VARHDRSZ )
75
75
{
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 */
80
77
len = strlen (s );
81
78
atttypmod = len + VARHDRSZ ;
82
79
}
83
80
else
84
81
len = atttypmod - VARHDRSZ ;
85
82
86
- if (len > MaxAttrSize )
87
- elog (ERROR , "bpcharin: length of char() must be less than %ld" ,
88
- MaxAttrSize );
89
-
90
83
result = (char * ) palloc (atttypmod );
91
84
VARSIZE (result ) = atttypmod ;
92
85
r = VARDATA (result );
@@ -149,15 +142,12 @@ bpchar(char *s, int32 len)
149
142
if (s == NULL )
150
143
return (char * ) NULL ;
151
144
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 ))
153
147
return s ;
154
148
155
149
rlen = len - VARHDRSZ ;
156
150
157
- if (rlen > MaxAttrSize )
158
- elog (ERROR , "bpchar: length of char() must be less than %ld" ,
159
- MaxAttrSize );
160
-
161
151
#ifdef STRINGDEBUG
162
152
printf ("bpchar- convert string length %d (%d) ->%d (%d)\n" ,
163
153
VARSIZE (s ) - VARHDRSZ , VARSIZE (s ), rlen , len );
@@ -333,13 +323,9 @@ varcharin(char *s, int dummy, int32 atttypmod)
333
323
return (char * ) NULL ;
334
324
335
325
len = strlen (s ) + VARHDRSZ ;
336
- if (atttypmod != -1 && len > atttypmod )
326
+ if (atttypmod >= ( int32 ) VARHDRSZ && len > atttypmod )
337
327
len = atttypmod ; /* clip the string at max length */
338
328
339
- if (len > MaxAttrSize )
340
- elog (ERROR , "varcharin: length of char() must be less than %ld" ,
341
- MaxAttrSize );
342
-
343
329
result = (char * ) palloc (len );
344
330
VARSIZE (result ) = len ;
345
331
strncpy (VARDATA (result ), s , len - VARHDRSZ );
@@ -391,7 +377,7 @@ varchar(char *s, int32 slen)
391
377
return (char * ) NULL ;
392
378
393
379
len = VARSIZE (s );
394
- if (( slen == -1 ) || ( len <= slen ) )
380
+ if (slen < ( int32 ) VARHDRSZ || len <= slen )
395
381
return (char * ) s ;
396
382
397
383
/* only reach here if we need to truncate string... */
@@ -408,10 +394,6 @@ varchar(char *s, int32 slen)
408
394
len = slen - VARHDRSZ ;
409
395
#endif
410
396
411
- if (len > MaxAttrSize )
412
- elog (ERROR , "varchar: length of varchar() must be less than %ld" ,
413
- MaxAttrSize );
414
-
415
397
result = (char * ) palloc (slen );
416
398
VARSIZE (result ) = slen ;
417
399
strncpy (VARDATA (result ), VARDATA (s ), len );
0 commit comments