Skip to content

Commit 0805953

Browse files
committed
phar: Restructure code to get rid of a goto
1 parent 40b3f88 commit 0805953

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

ext/phar/zip.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ zend_result phar_parse_zipfile(php_stream *fp, char *fname, size_t fname_len, ch
234234
uint16_t i;
235235
phar_archive_data *mydata = NULL;
236236
phar_entry_info entry = {0};
237-
char *p = buf, *ext, *actual_alias = NULL;
237+
char *ext, *actual_alias = NULL;
238238
char *metadata = NULL;
239239

240240
size = php_stream_tell(fp);
@@ -261,7 +261,16 @@ zend_result phar_parse_zipfile(php_stream *fp, char *fname, size_t fname_len, ch
261261
return FAILURE;
262262
}
263263

264-
if ((p = phar_find_eocd(buf, size)) != NULL) {
264+
char *p = phar_find_eocd(buf, size);
265+
if (!p) {
266+
php_stream_close(fp);
267+
if (error) {
268+
spprintf(error, 4096, "phar error: end of central directory not found in zip-based phar \"%s\"", fname);
269+
}
270+
return FAILURE;
271+
}
272+
273+
{
265274
memcpy((void *)&locator, (void *) p, sizeof(locator));
266275
if (PHAR_GET_16(locator.centraldisk) != 0 || PHAR_GET_16(locator.disknumber) != 0) {
267276
/* split archives not handled */
@@ -301,18 +310,8 @@ zend_result phar_parse_zipfile(php_stream *fp, char *fname, size_t fname_len, ch
301310
} else {
302311
ZVAL_UNDEF(&mydata->metadata_tracker.val);
303312
}
304-
305-
goto foundit;
306-
}
307-
308-
php_stream_close(fp);
309-
310-
if (error) {
311-
spprintf(error, 4096, "phar error: end of central directory not found in zip-based phar \"%s\"", fname);
312313
}
313314

314-
return FAILURE;
315-
foundit:
316315
mydata->fname = pestrndup(fname, fname_len, mydata->is_persistent);
317316
#ifdef PHP_WIN32
318317
phar_unixify_path_separators(mydata->fname, fname_len);

0 commit comments

Comments
 (0)