Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteb743d0

Browse files
committed
It seems appropriate that the extended MEMORY_CONTEXT_CHECKING code
immediately uncovered three of Karel's own bugs, including a routinethat scribbled on its input (naughty naughty!)
1 parentdd2b56d commiteb743d0

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

‎src/backend/utils/adt/formatting.c

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* -----------------------------------------------------------------------
22
* formatting.c
33
*
4-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.24 2000/11/25 05:00:29 momjian Exp $
4+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.25 2000/12/01 05:17:19 tgl Exp $
55
*
66
*
77
* Portions Copyright (c) 1999-2000, PostgreSQL, Inc
@@ -2521,7 +2521,7 @@ timestamp_to_char(PG_FUNCTION_ARGS)
25212521
tm->tm_yday=date2j(tm->tm_year,tm->tm_mon,tm->tm_mday)-date2j(tm->tm_year,1,1)+1;
25222522

25232523
/* ----------
2524-
* ConvertVARDATA() to string
2524+
* Convertfmt to C string
25252525
* ----------
25262526
*/
25272527
str= (char*)palloc(len+1);
@@ -2623,15 +2623,17 @@ timestamp_to_char(PG_FUNCTION_ARGS)
26232623
Datum
26242624
to_timestamp(PG_FUNCTION_ARGS)
26252625
{
2626-
text*date_str=PG_GETARG_TEXT_P(0);
2626+
text*date_txt=PG_GETARG_TEXT_P(0);
26272627
text*fmt=PG_GETARG_TEXT_P(1);
26282628
FormatNode*format;
26292629
intflag=0;
26302630
Timestampresult;
26312631
char*str;
2632-
intlen=0,
2633-
fsec=0,
2634-
tz=0;
2632+
char*date_str;
2633+
intlen,
2634+
date_len,
2635+
fsec=0,
2636+
tz=0;
26352637

26362638
ZERO_tm(tm);
26372639
ZERO_tmfc(tmfc);
@@ -2642,7 +2644,7 @@ to_timestamp(PG_FUNCTION_ARGS)
26422644
{
26432645

26442646
/* ----------
2645-
* ConvertVARDATA() to string
2647+
* Convertfmt to C string
26462648
* ----------
26472649
*/
26482650
str= (char*)palloc(len+1);
@@ -2704,11 +2706,20 @@ to_timestamp(PG_FUNCTION_ARGS)
27042706
#ifdefDEBUG_TO_FROM_CHAR
27052707
/* dump_node(format, len); */
27062708
#endif
2707-
VARDATA(date_str)[VARSIZE(date_str)-VARHDRSZ]='\0';
2708-
DCH_processor(format,VARDATA(date_str),FROM_CHAR);
27092709

2710-
pfree(str);
2710+
/* ----------
2711+
* Convert date to C string
2712+
* ----------
2713+
*/
2714+
date_len=VARSIZE(date_txt)-VARHDRSZ;
2715+
date_str= (char*)palloc(date_len+1);
2716+
memcpy(date_str,VARDATA(date_txt),date_len);
2717+
*(date_str+date_len)='\0';
27112718

2719+
DCH_processor(format,date_str,FROM_CHAR);
2720+
2721+
pfree(date_str);
2722+
pfree(str);
27122723
if (flag)
27132724
pfree(format);
27142725
}
@@ -4325,13 +4336,13 @@ int4_to_char(PG_FUNCTION_ARGS)
43254336
{
43264337
inti;
43274338

4328-
numstr=palloc(len+1+Num.post);
4339+
numstr=(char*)palloc(len+Num.post+2);
43294340
strcpy(numstr,orgnum+ (*orgnum=='-' ?1 :0));
43304341
*(numstr+len)='.';
43314342

4332-
for (i=len+1;i <=Num.post+len+1;i++)
4343+
for (i=len+1;i <=len+Num.post;i++)
43334344
*(numstr+i)='0';
4334-
*(numstr+Num.post+len+1)='\0';
4345+
*(numstr+len+Num.post+1)='\0';
43354346
pfree(orgnum);
43364347
orgnum=numstr;
43374348
}
@@ -4413,13 +4424,13 @@ int8_to_char(PG_FUNCTION_ARGS)
44134424
{
44144425
inti;
44154426

4416-
numstr=palloc(len+1+Num.post);
4427+
numstr=(char*)palloc(len+Num.post+2);
44174428
strcpy(numstr,orgnum+ (*orgnum=='-' ?1 :0));
44184429
*(numstr+len)='.';
44194430

4420-
for (i=len+1;i <=Num.post+len+1;i++)
4431+
for (i=len+1;i <=len+Num.post;i++)
44214432
*(numstr+i)='0';
4422-
*(numstr+Num.post+len+1)='\0';
4433+
*(numstr+len+Num.post+1)='\0';
44234434
pfree(orgnum);
44244435
orgnum=numstr;
44254436
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp