Skip to content

Commit 2fab143

Browse files
committed
Cleanup php_libxml_streams_IO_open_wrapper()
1 parent a54d63a commit 2fab143

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

ext/libxml/libxml.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -389,20 +389,16 @@ PHP_LIBXML_API php_stream_context *php_libxml_get_stream_context(void)
389389
static void *php_libxml_streams_IO_open_wrapper(const char *filename, const char *mode, const int read_only)
390390
{
391391
php_stream_statbuf ssbuf;
392-
php_stream_context *context = NULL;
393-
php_stream_wrapper *wrapper = NULL;
394392
char *resolved_path;
395393
const char *path_to_open = NULL;
396-
void *ret_val = NULL;
397-
int isescaped=0;
398-
xmlURI *uri;
394+
bool isescaped = false;
399395

400396
if (strstr(filename, "%00")) {
401397
php_error_docref(NULL, E_WARNING, "URI must not contain percent-encoded NUL bytes");
402398
return NULL;
403399
}
404400

405-
uri = xmlParseURI(filename);
401+
xmlURI *uri = xmlParseURI(filename);
406402
if (uri && (uri->scheme == NULL ||
407403
(xmlStrncmp(BAD_CAST uri->scheme, BAD_CAST "file", 4) == 0))) {
408404
resolved_path = xmlURIUnescapeString(filename, 0, NULL);
@@ -440,7 +436,7 @@ static void *php_libxml_streams_IO_open_wrapper(const char *filename, const char
440436
that the streams layer puts out at times, but for libxml we
441437
may try to open files that don't exist, but it is not a failure
442438
in xml processing (eg. DTD files) */
443-
wrapper = php_stream_locate_url_wrapper(resolved_path, &path_to_open, 0);
439+
php_stream_wrapper *wrapper = php_stream_locate_url_wrapper(resolved_path, &path_to_open, 0);
444440
if (wrapper && read_only && wrapper->wops->url_stat) {
445441
if (wrapper->wops->url_stat(wrapper, path_to_open, PHP_STREAM_URL_STAT_QUIET, &ssbuf, NULL) == -1) {
446442
if (isescaped) {
@@ -450,12 +446,12 @@ static void *php_libxml_streams_IO_open_wrapper(const char *filename, const char
450446
}
451447
}
452448

453-
context = php_libxml_get_stream_context();
449+
php_stream_context *context = php_libxml_get_stream_context();
454450

455-
ret_val = php_stream_open_wrapper_ex(path_to_open, (char *)mode, REPORT_ERRORS, NULL, context);
451+
php_stream *ret_val = php_stream_open_wrapper_ex(path_to_open, mode, REPORT_ERRORS, NULL, context);
456452
if (ret_val) {
457453
/* Prevent from closing this by fclose() */
458-
((php_stream*)ret_val)->flags |= PHP_STREAM_FLAG_NO_FCLOSE;
454+
ret_val->flags |= PHP_STREAM_FLAG_NO_FCLOSE;
459455
}
460456
if (isescaped) {
461457
xmlFree(resolved_path);

0 commit comments

Comments
 (0)