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

Commit9300188

Browse files
committed
Fix up misuse of "volatile" in contrib/xml2.
What we want in these places is "xmlChar *volatile ptr",not "volatile xmlChar *ptr". The former means that thepointer variable itself needs to be treated as volatile,while the latter says that what it points to is volatile.Since the point here is to ensure that the pointer variablesdon't go crazy after a longjmp, it's the former semanticsthat we need. The misplacement of "volatile" also ledto needing to cast away volatile in some places.Also fix a number of places where variables that are assigned towithin a PG_TRY and then used after it were not initialized ornot marked as volatile. (A few buildfarm members were issuing"may be used uninitialized" warnings about some of these variables,which is what drew my attention to this area.) In most casesthese variables were being set as the last step within the PG_TRYblock, which might mean that we could get away without the "volatile"marking. But doing that seems unsafe and is definitely not per ourcoding conventions.These problems seem to have come in with7320611, so no needfor back-patch.
1 parente03c952 commit9300188

File tree

2 files changed

+29
-30
lines changed

2 files changed

+29
-30
lines changed

‎contrib/xml2/xpath.c

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static xmlChar *pgxml_texttoxmlchar(text *textstring);
5454
staticxpath_workspace*pgxml_xpath(text*document,xmlChar*xpath,
5555
PgXmlErrorContext*xmlerrcxt);
5656

57-
staticvoidcleanup_workspace(volatilexpath_workspace*workspace);
57+
staticvoidcleanup_workspace(xpath_workspace*workspace);
5858

5959

6060
/*
@@ -88,8 +88,8 @@ Datum
8888
xml_encode_special_chars(PG_FUNCTION_ARGS)
8989
{
9090
text*tin=PG_GETARG_TEXT_PP(0);
91-
text*tout;
92-
volatilexmlChar*tt=NULL;
91+
text*volatiletout=NULL;
92+
xmlChar*volatilett=NULL;
9393
PgXmlErrorContext*xmlerrcxt;
9494

9595
xmlerrcxt=pg_xml_init(PG_XML_STRICTNESS_ALL);
@@ -111,7 +111,7 @@ xml_encode_special_chars(PG_FUNCTION_ARGS)
111111
PG_CATCH();
112112
{
113113
if (tt!=NULL)
114-
xmlFree((xmlChar*)tt);
114+
xmlFree(tt);
115115

116116
pg_xml_done(xmlerrcxt, true);
117117

@@ -120,7 +120,7 @@ xml_encode_special_chars(PG_FUNCTION_ARGS)
120120
PG_END_TRY();
121121

122122
if (tt!=NULL)
123-
xmlFree((xmlChar*)tt);
123+
xmlFree(tt);
124124

125125
pg_xml_done(xmlerrcxt, false);
126126

@@ -145,11 +145,10 @@ pgxmlNodeSetToText(xmlNodeSetPtr nodeset,
145145
xmlChar*plainsep)
146146
{
147147
volatilexmlBufferPtrbuf=NULL;
148-
xmlChar*result;
149-
inti;
148+
xmlChar*volatileresult=NULL;
150149
PgXmlErrorContext*xmlerrcxt;
151150

152-
/* spin some error handling */
151+
/* spinupsome error handling */
153152
xmlerrcxt=pg_xml_init(PG_XML_STRICTNESS_ALL);
154153

155154
PG_TRY();
@@ -168,7 +167,7 @@ pgxmlNodeSetToText(xmlNodeSetPtr nodeset,
168167
}
169168
if (nodeset!=NULL)
170169
{
171-
for (i=0;i<nodeset->nodeNr;i++)
170+
for (inti=0;i<nodeset->nodeNr;i++)
172171
{
173172
if (plainsep!=NULL)
174173
{
@@ -257,8 +256,8 @@ xpath_nodeset(PG_FUNCTION_ARGS)
257256
xmlChar*toptag=pgxml_texttoxmlchar(PG_GETARG_TEXT_PP(2));
258257
xmlChar*septag=pgxml_texttoxmlchar(PG_GETARG_TEXT_PP(3));
259258
xmlChar*xpath;
260-
text*xpres;
261-
volatilexpath_workspace*workspace;
259+
text*volatilexpres=NULL;
260+
xpath_workspace*volatileworkspace=NULL;
262261
PgXmlErrorContext*xmlerrcxt;
263262

264263
xpath=pgxml_texttoxmlchar(xpathsupp);
@@ -302,8 +301,8 @@ xpath_list(PG_FUNCTION_ARGS)
302301
text*xpathsupp=PG_GETARG_TEXT_PP(1);/* XPath expression */
303302
xmlChar*plainsep=pgxml_texttoxmlchar(PG_GETARG_TEXT_PP(2));
304303
xmlChar*xpath;
305-
text*xpres;
306-
volatilexpath_workspace*workspace;
304+
text*volatilexpres=NULL;
305+
xpath_workspace*volatileworkspace=NULL;
307306
PgXmlErrorContext*xmlerrcxt;
308307

309308
xpath=pgxml_texttoxmlchar(xpathsupp);
@@ -344,8 +343,8 @@ xpath_string(PG_FUNCTION_ARGS)
344343
text*xpathsupp=PG_GETARG_TEXT_PP(1);/* XPath expression */
345344
xmlChar*xpath;
346345
int32pathsize;
347-
text*xpres;
348-
volatilexpath_workspace*workspace;
346+
text*volatilexpres=NULL;
347+
xpath_workspace*volatileworkspace=NULL;
349348
PgXmlErrorContext*xmlerrcxt;
350349

351350
pathsize=VARSIZE_ANY_EXHDR(xpathsupp);
@@ -398,9 +397,9 @@ xpath_number(PG_FUNCTION_ARGS)
398397
text*document=PG_GETARG_TEXT_PP(0);
399398
text*xpathsupp=PG_GETARG_TEXT_PP(1);/* XPath expression */
400399
xmlChar*xpath;
401-
float4fRes=0.0;
402-
boolisNull= false;
403-
volatilexpath_workspace*workspace=NULL;
400+
volatilefloat4fRes=0.0;
401+
volatileboolisNull= false;
402+
xpath_workspace*volatileworkspace=NULL;
404403
PgXmlErrorContext*xmlerrcxt;
405404

406405
xpath=pgxml_texttoxmlchar(xpathsupp);
@@ -444,8 +443,8 @@ xpath_bool(PG_FUNCTION_ARGS)
444443
text*document=PG_GETARG_TEXT_PP(0);
445444
text*xpathsupp=PG_GETARG_TEXT_PP(1);/* XPath expression */
446445
xmlChar*xpath;
447-
intbRes;
448-
volatilexpath_workspace*workspace=NULL;
446+
volatileintbRes=0;
447+
xpath_workspace*volatileworkspace=NULL;
449448
PgXmlErrorContext*xmlerrcxt;
450449

451450
xpath=pgxml_texttoxmlchar(xpathsupp);
@@ -518,7 +517,7 @@ pgxml_xpath(text *document, xmlChar *xpath, PgXmlErrorContext *xmlerrcxt)
518517

519518
/* Clean up after processing the result of pgxml_xpath() */
520519
staticvoid
521-
cleanup_workspace(volatilexpath_workspace*workspace)
520+
cleanup_workspace(xpath_workspace*workspace)
522521
{
523522
if (workspace->res)
524523
xmlXPathFreeObject(workspace->res);
@@ -537,9 +536,9 @@ pgxml_result_to_text(xmlXPathObjectPtr res,
537536
xmlChar*septag,
538537
xmlChar*plainsep)
539538
{
540-
volatilexmlChar*xpresstr=NULL;
539+
xmlChar*volatilexpresstr=NULL;
540+
text*volatilexpres=NULL;
541541
PgXmlErrorContext*xmlerrcxt;
542-
text*xpres;
543542

544543
if (res==NULL)
545544
returnNULL;
@@ -578,7 +577,7 @@ pgxml_result_to_text(xmlXPathObjectPtr res,
578577
PG_CATCH();
579578
{
580579
if (xpresstr!=NULL)
581-
xmlFree((xmlChar*)xpresstr);
580+
xmlFree(xpresstr);
582581

583582
pg_xml_done(xmlerrcxt, true);
584583

@@ -587,7 +586,7 @@ pgxml_result_to_text(xmlXPathObjectPtr res,
587586
PG_END_TRY();
588587

589588
/* Free various storage */
590-
xmlFree((xmlChar*)xpresstr);
589+
xmlFree(xpresstr);
591590

592591
pg_xml_done(xmlerrcxt, false);
593592

‎contrib/xml2/xslt_proc.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ xslt_process(PG_FUNCTION_ARGS)
4848

4949
text*doct=PG_GETARG_TEXT_PP(0);
5050
text*ssheet=PG_GETARG_TEXT_PP(1);
51-
text*result;
51+
text*volatileresult=NULL;
5252
text*paramstr;
5353
constchar**params;
5454
PgXmlErrorContext*xmlerrcxt;
@@ -58,8 +58,7 @@ xslt_process(PG_FUNCTION_ARGS)
5858
volatilexsltSecurityPrefsPtrxslt_sec_prefs=NULL;
5959
volatilexsltTransformContextPtrxslt_ctxt=NULL;
6060
volatileintresstat=-1;
61-
volatilexmlChar*resstr=NULL;
62-
intreslen=0;
61+
xmlChar*volatileresstr=NULL;
6362

6463
if (fcinfo->nargs==3)
6564
{
@@ -80,6 +79,7 @@ xslt_process(PG_FUNCTION_ARGS)
8079
{
8180
xmlDocPtrssdoc;
8281
boolxslt_sec_prefs_error;
82+
intreslen=0;
8383

8484
/* Parse document */
8585
doctree=xmlReadMemory((char*)VARDATA_ANY(doct),
@@ -160,7 +160,7 @@ xslt_process(PG_FUNCTION_ARGS)
160160
if (doctree!=NULL)
161161
xmlFreeDoc(doctree);
162162
if (resstr!=NULL)
163-
xmlFree((xmlChar*)resstr);
163+
xmlFree(resstr);
164164
xsltCleanupGlobals();
165165

166166
pg_xml_done(xmlerrcxt, true);
@@ -177,7 +177,7 @@ xslt_process(PG_FUNCTION_ARGS)
177177
xsltCleanupGlobals();
178178

179179
if (resstr)
180-
xmlFree((xmlChar*)resstr);
180+
xmlFree(resstr);
181181

182182
pg_xml_done(xmlerrcxt, false);
183183

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp