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

Commitfccde77

Browse files
committed
Prevent to_char(interval) from dumping core on month-related formats
when a zero-month interval is given. Per discussion with Karel.Also, some desultory const-labeling of constant tables. More could bedone along that line.
1 parenta703269 commitfccde77

File tree

1 file changed

+41
-25
lines changed

1 file changed

+41
-25
lines changed

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

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* -----------------------------------------------------------------------
22
* formatting.c
33
*
4-
* $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.85 2005/03/25 16:08:40 tgl Exp $
4+
* $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.86 2005/03/26 00:41:31 tgl Exp $
55
*
66
*
77
* Portions Copyright (c) 1999-2005, PostgreSQL Global Development Group
@@ -133,18 +133,19 @@ typedef struct FormatNode FormatNode;
133133

134134
typedefstruct
135135
{
136-
char*name;/* keyword*/
137-
/* action for keyword*/
138-
intlen,/* keyword length*/
139-
(*action) (intarg,char*inout,intsuf,intflag,FormatNode*node,void*data),
140-
id;/* keyword id*/
136+
constchar*name;/* keyword*/
137+
intlen;/* keyword length*/
138+
int (*action) (intarg,char*inout,/* action for keyword */
139+
intsuf,intflag,
140+
FormatNode*node,void*data);
141+
intid;/* keyword id*/
141142
boolisitdigit;/* is expected output/input digit */
142143
}KeyWord;
143144

144145
structFormatNode
145146
{
146147
inttype;/* node type*/
147-
KeyWord*key;/* if node type is KEYWORD*/
148+
constKeyWord*key;/* if node type is KEYWORD*/
148149
intcharacter,/* if node type is CHAR*/
149150
suffix;/* keyword suffix*/
150151
};
@@ -648,7 +649,7 @@ typedef enum
648649
* KeyWords for DATE-TIME version
649650
* ----------
650651
*/
651-
staticKeyWordDCH_keywords[]= {
652+
staticconstKeyWordDCH_keywords[]= {
652653
/*keyword, len, func, type, isitdigit is in Index */
653654
{"A.D.",4,dch_date,DCH_A_D, FALSE},/* A */
654655
{"A.M.",4,dch_time,DCH_A_M, FALSE},
@@ -745,7 +746,7 @@ static KeyWord DCH_keywords[] = {
745746
* KeyWords for NUMBER version (now, isitdigit info is not needful here..)
746747
* ----------
747748
*/
748-
staticKeyWordNUM_keywords[]= {
749+
staticconstKeyWordNUM_keywords[]= {
749750
/*keyword,len, func.type is in Index */
750751
{",",1,NULL,NUM_COMMA},/* , */
751752
{".",1,NULL,NUM_DEC},/* . */
@@ -792,7 +793,7 @@ static KeyWord NUM_keywords[] = {
792793
* KeyWords index for DATE-TIME version
793794
* ----------
794795
*/
795-
staticintDCH_index[KeyWord_INDEX_SIZE]= {
796+
staticconstintDCH_index[KeyWord_INDEX_SIZE]= {
796797
/*
797798
0123456789
798799
*/
@@ -816,7 +817,7 @@ static intDCH_index[KeyWord_INDEX_SIZE] = {
816817
* KeyWords index for NUMBER version
817818
* ----------
818819
*/
819-
staticintNUM_index[KeyWord_INDEX_SIZE]= {
820+
staticconstintNUM_index[KeyWord_INDEX_SIZE]= {
820821
/*
821822
0123456789
822823
*/
@@ -876,15 +877,16 @@ typedef struct NUMProc
876877
* Functions
877878
* ----------
878879
*/
879-
staticKeyWord*index_seq_search(char*str,KeyWord*kw,int*index);
880+
staticconstKeyWord*index_seq_search(char*str,constKeyWord*kw,
881+
constint*index);
880882
staticKeySuffix*suff_search(char*str,KeySuffix*suf,inttype);
881883
staticvoidNUMDesc_prepare(NUMDesc*num,FormatNode*n);
882-
staticvoidparse_format(FormatNode*node,char*str,KeyWord*kw,
883-
KeySuffix*suf,int*index,intver,NUMDesc*Num);
884+
staticvoidparse_format(FormatNode*node,char*str,constKeyWord*kw,
885+
KeySuffix*suf,constint*index,intver,NUMDesc*Num);
884886
staticchar*DCH_processor(FormatNode*node,char*inout,intflag,void*data);
885887

886888
#ifdefDEBUG_TO_FROM_CHAR
887-
staticvoiddump_index(KeyWord*k,int*index);
889+
staticvoiddump_index(constKeyWord*k,constint*index);
888890
staticvoiddump_node(FormatNode*node,intmax);
889891
#endif
890892

@@ -924,8 +926,8 @@ static void NUM_cache_remove(NUMCacheEntry *ent);
924926
* (can't be used binary search in format parsing)
925927
* ----------
926928
*/
927-
staticKeyWord*
928-
index_seq_search(char*str,KeyWord*kw,int*index)
929+
staticconstKeyWord*
930+
index_seq_search(char*str,constKeyWord*kw,constint*index)
929931
{
930932
intpoz;
931933

@@ -934,8 +936,7 @@ index_seq_search(char *str, KeyWord *kw, int *index)
934936

935937
if ((poz=*(index+ (*str-' ')))>-1)
936938
{
937-
938-
KeyWord*k=kw+poz;
939+
constKeyWord*k=kw+poz;
939940

940941
do
941942
{
@@ -1167,8 +1168,8 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)
11671168
* ----------
11681169
*/
11691170
staticvoid
1170-
parse_format(FormatNode*node,char*str,KeyWord*kw,
1171-
KeySuffix*suf,int*index,intver,NUMDesc*Num)
1171+
parse_format(FormatNode*node,char*str,constKeyWord*kw,
1172+
KeySuffix*suf,constint*index,intver,NUMDesc*Num)
11721173
{
11731174
KeySuffix*s;
11741175
FormatNode*n;
@@ -1594,7 +1595,7 @@ seq_search(char *name, char **array, int type, int max, int *len)
15941595
* ----------
15951596
*/
15961597
staticvoid
1597-
dump_index(KeyWord*k,int*index)
1598+
dump_index(constKeyWord*k,constint*index)
15981599
{
15991600
inti,
16001601
count=0,
@@ -2182,6 +2183,8 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
21822183
}
21832184
break;
21842185
caseDCH_MONTH:
2186+
if (!tm->tm_mon)
2187+
return-1;
21852188
strcpy(workbuff,months_full[tm->tm_mon-1]);
21862189
sprintf(inout,"%*s",S_FM(suf) ?0 :-9,str_toupper(workbuff));
21872190
if (S_FM(suf))
@@ -2190,13 +2193,17 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
21902193
return8;
21912194

21922195
caseDCH_Month:
2196+
if (!tm->tm_mon)
2197+
return-1;
21932198
sprintf(inout,"%*s",S_FM(suf) ?0 :-9,months_full[tm->tm_mon-1]);
21942199
if (S_FM(suf))
21952200
returnstrlen(p_inout)-1;
21962201
else
21972202
return8;
21982203

21992204
caseDCH_month:
2205+
if (!tm->tm_mon)
2206+
return-1;
22002207
sprintf(inout,"%*s",S_FM(suf) ?0 :-9,months_full[tm->tm_mon-1]);
22012208
*inout=pg_tolower((unsignedchar)*inout);
22022209
if (S_FM(suf))
@@ -2205,15 +2212,21 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
22052212
return8;
22062213

22072214
caseDCH_MON:
2215+
if (!tm->tm_mon)
2216+
return-1;
22082217
strcpy(inout,months[tm->tm_mon-1]);
22092218
inout=str_toupper(inout);
22102219
return2;
22112220

22122221
caseDCH_Mon:
2222+
if (!tm->tm_mon)
2223+
return-1;
22132224
strcpy(inout,months[tm->tm_mon-1]);
22142225
return2;
22152226

22162227
caseDCH_mon:
2228+
if (!tm->tm_mon)
2229+
return-1;
22172230
strcpy(inout,months[tm->tm_mon-1]);
22182231
*inout=pg_tolower((unsignedchar)*inout);
22192232
return2;
@@ -2228,7 +2241,6 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
22282241
returnstrlen(p_inout)-1;
22292242
else
22302243
return1;
2231-
22322244
}
22332245
elseif (flag==FROM_CHAR)
22342246
{
@@ -2388,7 +2400,6 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
23882400
returnstrlen(p_inout)-1;
23892401
else
23902402
return1;
2391-
23922403
}
23932404
elseif (flag==FROM_CHAR)
23942405
{
@@ -2407,14 +2418,15 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
24072418
caseDCH_Q:
24082419
if (flag==TO_CHAR)
24092420
{
2421+
if (!tm->tm_mon)
2422+
return-1;
24102423
sprintf(inout,"%d", (tm->tm_mon-1) /3+1);
24112424
if (S_THth(suf))
24122425
{
24132426
str_numth(p_inout,inout,S_TH_TYPE(suf));
24142427
return2;
24152428
}
24162429
return0;
2417-
24182430
}
24192431
elseif (flag==FROM_CHAR)
24202432
{
@@ -2613,6 +2625,8 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
26132625
caseDCH_RM:
26142626
if (flag==TO_CHAR)
26152627
{
2628+
if (!tm->tm_mon)
2629+
return-1;
26162630
sprintf(inout,"%*s",S_FM(suf) ?0 :-4,
26172631
rm_months_upper[12-tm->tm_mon]);
26182632
if (S_FM(suf))
@@ -2634,6 +2648,8 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
26342648
caseDCH_rm:
26352649
if (flag==TO_CHAR)
26362650
{
2651+
if (!tm->tm_mon)
2652+
return-1;
26372653
sprintf(inout,"%*s",S_FM(suf) ?0 :-4,
26382654
rm_months_lower[12-tm->tm_mon]);
26392655
if (S_FM(suf))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp