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

Commitc7a1c5a

Browse files
committed
Cosmetic improvements in new config_info code.
Coverity griped about use of unchecked strcpy() into a local variable.There's unlikely to be any actual bug there, since no caller would bepassing a path longer than MAXPGPATH, but nonetheless use of strlcpy()seems preferable.While at it, get rid of unmaintainable separation between list offield names and list of field values in favor of initializing themin parallel. And we might as well declare get_configdata()'s pathargument as const char *, even though no current caller needs that.
1 parent94c745e commitc7a1c5a

File tree

2 files changed

+89
-89
lines changed

2 files changed

+89
-89
lines changed

‎src/common/config_info.c

Lines changed: 88 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -20,187 +20,187 @@
2020
#include"postgres_fe.h"
2121
#endif
2222

23-
#include"miscadmin.h"
2423
#include"common/config_info.h"
24+
#include"miscadmin.h"
2525

26-
staticsize_tconfigdata_names_len(void);
27-
28-
staticconstchar*constconfigdata_names[]=
29-
{
30-
"BINDIR",
31-
"DOCDIR",
32-
"HTMLDIR",
33-
"INCLUDEDIR",
34-
"PKGINCLUDEDIR",
35-
"INCLUDEDIR-SERVER",
36-
"LIBDIR",
37-
"PKGLIBDIR",
38-
"LOCALEDIR",
39-
"MANDIR",
40-
"SHAREDIR",
41-
"SYSCONFDIR",
42-
"PGXS",
43-
"CONFIGURE",
44-
"CC",
45-
"CPPFLAGS",
46-
"CFLAGS",
47-
"CFLAGS_SL",
48-
"LDFLAGS",
49-
"LDFLAGS_EX",
50-
"LDFLAGS_SL",
51-
"LIBS",
52-
"VERSION",
53-
NULL
54-
};
55-
56-
staticsize_t
57-
configdata_names_len(void)
58-
{
59-
size_ti=0;
60-
61-
while (configdata_names[i])
62-
i++;
63-
64-
returni;
65-
}
6626

6727
/*
68-
* get_configdata(char *my_exec_path, size_t *configdata_len)
28+
* get_configdata(constchar *my_exec_path, size_t *configdata_len)
6929
*
7030
* Get configure-time constants. The caller is responsible
7131
* for pfreeing the result.
7232
*/
7333
ConfigData*
74-
get_configdata(char*my_exec_path,size_t*configdata_len)
34+
get_configdata(constchar*my_exec_path,size_t*configdata_len)
7535
{
7636
ConfigData*configdata;
7737
charpath[MAXPGPATH];
7838
char*lastsep;
79-
inti;
39+
inti=0;
8040

81-
*configdata_len=configdata_names_len();
82-
configdata=palloc(*configdata_len*sizeof(ConfigData));
41+
/* Adjust this to match the number of items filled below */
42+
*configdata_len=23;
43+
configdata= (ConfigData*)palloc(*configdata_len*sizeof(ConfigData));
8344

84-
/*
85-
* initialize configdata names
86-
*
87-
* These better be in sync with the settings manually
88-
* defined below.
89-
*/
90-
for (i=0;i<*configdata_len;i++)
91-
configdata[i].name=pstrdup(configdata_names[i]);
92-
93-
strcpy(path,my_exec_path);
45+
configdata[i].name=pstrdup("BINDIR");
46+
strlcpy(path,my_exec_path,sizeof(path));
9447
lastsep=strrchr(path,'/');
9548
if (lastsep)
9649
*lastsep='\0';
9750
cleanup_path(path);
98-
configdata[0].setting=pstrdup(path);
51+
configdata[i].setting=pstrdup(path);
52+
i++;
9953

54+
configdata[i].name=pstrdup("DOCDIR");
10055
get_doc_path(my_exec_path,path);
10156
cleanup_path(path);
102-
configdata[1].setting=pstrdup(path);
57+
configdata[i].setting=pstrdup(path);
58+
i++;
10359

60+
configdata[i].name=pstrdup("HTMLDIR");
10461
get_html_path(my_exec_path,path);
10562
cleanup_path(path);
106-
configdata[2].setting=pstrdup(path);
63+
configdata[i].setting=pstrdup(path);
64+
i++;
10765

66+
configdata[i].name=pstrdup("INCLUDEDIR");
10867
get_include_path(my_exec_path,path);
10968
cleanup_path(path);
110-
configdata[3].setting=pstrdup(path);
69+
configdata[i].setting=pstrdup(path);
70+
i++;
11171

72+
configdata[i].name=pstrdup("PKGINCLUDEDIR");
11273
get_pkginclude_path(my_exec_path,path);
11374
cleanup_path(path);
114-
configdata[4].setting=pstrdup(path);
75+
configdata[i].setting=pstrdup(path);
76+
i++;
11577

78+
configdata[i].name=pstrdup("INCLUDEDIR-SERVER");
11679
get_includeserver_path(my_exec_path,path);
11780
cleanup_path(path);
118-
configdata[5].setting=pstrdup(path);
81+
configdata[i].setting=pstrdup(path);
82+
i++;
11983

84+
configdata[i].name=pstrdup("LIBDIR");
12085
get_lib_path(my_exec_path,path);
12186
cleanup_path(path);
122-
configdata[6].setting=pstrdup(path);
87+
configdata[i].setting=pstrdup(path);
88+
i++;
12389

90+
configdata[i].name=pstrdup("PKGLIBDIR");
12491
get_pkglib_path(my_exec_path,path);
12592
cleanup_path(path);
126-
configdata[7].setting=pstrdup(path);
93+
configdata[i].setting=pstrdup(path);
94+
i++;
12795

96+
configdata[i].name=pstrdup("LOCALEDIR");
12897
get_locale_path(my_exec_path,path);
12998
cleanup_path(path);
130-
configdata[8].setting=pstrdup(path);
99+
configdata[i].setting=pstrdup(path);
100+
i++;
131101

102+
configdata[i].name=pstrdup("MANDIR");
132103
get_man_path(my_exec_path,path);
133104
cleanup_path(path);
134-
configdata[9].setting=pstrdup(path);
105+
configdata[i].setting=pstrdup(path);
106+
i++;
135107

108+
configdata[i].name=pstrdup("SHAREDIR");
136109
get_share_path(my_exec_path,path);
137110
cleanup_path(path);
138-
configdata[10].setting=pstrdup(path);
111+
configdata[i].setting=pstrdup(path);
112+
i++;
139113

114+
configdata[i].name=pstrdup("SYSCONFDIR");
140115
get_etc_path(my_exec_path,path);
141116
cleanup_path(path);
142-
configdata[11].setting=pstrdup(path);
117+
configdata[i].setting=pstrdup(path);
118+
i++;
143119

120+
configdata[i].name=pstrdup("PGXS");
144121
get_pkglib_path(my_exec_path,path);
145122
strlcat(path,"/pgxs/src/makefiles/pgxs.mk",sizeof(path));
146123
cleanup_path(path);
147-
configdata[12].setting=pstrdup(path);
124+
configdata[i].setting=pstrdup(path);
125+
i++;
148126

127+
configdata[i].name=pstrdup("CONFIGURE");
149128
#ifdefVAL_CONFIGURE
150-
configdata[13].setting=pstrdup(VAL_CONFIGURE);
129+
configdata[i].setting=pstrdup(VAL_CONFIGURE);
151130
#else
152-
configdata[13].setting=pstrdup(_("not recorded"));
131+
configdata[i].setting=pstrdup(_("not recorded"));
153132
#endif
133+
i++;
154134

135+
configdata[i].name=pstrdup("CC");
155136
#ifdefVAL_CC
156-
configdata[14].setting=pstrdup(VAL_CC);
137+
configdata[i].setting=pstrdup(VAL_CC);
157138
#else
158-
configdata[14].setting=pstrdup(_("not recorded"));
139+
configdata[i].setting=pstrdup(_("not recorded"));
159140
#endif
141+
i++;
160142

143+
configdata[i].name=pstrdup("CPPFLAGS");
161144
#ifdefVAL_CPPFLAGS
162-
configdata[15].setting=pstrdup(VAL_CPPFLAGS);
145+
configdata[i].setting=pstrdup(VAL_CPPFLAGS);
163146
#else
164-
configdata[15].setting=pstrdup(_("not recorded"));
147+
configdata[i].setting=pstrdup(_("not recorded"));
165148
#endif
149+
i++;
166150

151+
configdata[i].name=pstrdup("CFLAGS");
167152
#ifdefVAL_CFLAGS
168-
configdata[16].setting=pstrdup(VAL_CFLAGS);
153+
configdata[i].setting=pstrdup(VAL_CFLAGS);
169154
#else
170-
configdata[16].setting=pstrdup(_("not recorded"));
155+
configdata[i].setting=pstrdup(_("not recorded"));
171156
#endif
157+
i++;
172158

159+
configdata[i].name=pstrdup("CFLAGS_SL");
173160
#ifdefVAL_CFLAGS_SL
174-
configdata[17].setting=pstrdup(VAL_CFLAGS_SL);
161+
configdata[i].setting=pstrdup(VAL_CFLAGS_SL);
175162
#else
176-
configdata[17].setting=pstrdup(_("not recorded"));
163+
configdata[i].setting=pstrdup(_("not recorded"));
177164
#endif
165+
i++;
178166

167+
configdata[i].name=pstrdup("LDFLAGS");
179168
#ifdefVAL_LDFLAGS
180-
configdata[18].setting=pstrdup(VAL_LDFLAGS);
169+
configdata[i].setting=pstrdup(VAL_LDFLAGS);
181170
#else
182-
configdata[18].setting=pstrdup(_("not recorded"));
171+
configdata[i].setting=pstrdup(_("not recorded"));
183172
#endif
173+
i++;
184174

175+
configdata[i].name=pstrdup("LDFLAGS_EX");
185176
#ifdefVAL_LDFLAGS_EX
186-
configdata[19].setting=pstrdup(VAL_LDFLAGS_EX);
177+
configdata[i].setting=pstrdup(VAL_LDFLAGS_EX);
187178
#else
188-
configdata[19].setting=pstrdup(_("not recorded"));
179+
configdata[i].setting=pstrdup(_("not recorded"));
189180
#endif
181+
i++;
190182

183+
configdata[i].name=pstrdup("LDFLAGS_SL");
191184
#ifdefVAL_LDFLAGS_SL
192-
configdata[20].setting=pstrdup(VAL_LDFLAGS_SL);
185+
configdata[i].setting=pstrdup(VAL_LDFLAGS_SL);
193186
#else
194-
configdata[20].setting=pstrdup(_("not recorded"));
187+
configdata[i].setting=pstrdup(_("not recorded"));
195188
#endif
189+
i++;
196190

191+
configdata[i].name=pstrdup("LIBS");
197192
#ifdefVAL_LIBS
198-
configdata[21].setting=pstrdup(VAL_LIBS);
193+
configdata[i].setting=pstrdup(VAL_LIBS);
199194
#else
200-
configdata[21].setting=pstrdup(_("not recorded"));
195+
configdata[i].setting=pstrdup(_("not recorded"));
201196
#endif
197+
i++;
198+
199+
configdata[i].name=pstrdup("VERSION");
200+
configdata[i].setting=pstrdup("PostgreSQL "PG_VERSION);
201+
i++;
202202

203-
configdata[22].setting=pstrdup("PostgreSQL "PG_VERSION);
203+
Assert(i==*configdata_len);
204204

205205
returnconfigdata;
206206
}

‎src/include/common/config_info.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ typedef struct ConfigData
1515
char*setting;
1616
}ConfigData;
1717

18-
externConfigData*get_configdata(char*my_exec_path,
18+
externConfigData*get_configdata(constchar*my_exec_path,
1919
size_t*configdata_len);
2020

2121
#endif/* COMMON_CONFIG_INFO_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp