Skip to content

Commit b75c79e

Browse files
committed
ext/phar: Use bool instead of int
1 parent 03e2cfd commit b75c79e

File tree

3 files changed

+52
-50
lines changed

3 files changed

+52
-50
lines changed

ext/phar/phar.c

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2535,8 +2535,9 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
25352535
zend_string *newstub;
25362536
phar_entry_info *entry, *newentry;
25372537
size_t halt_offset;
2538-
int restore_alias_len, global_flags = 0, closeoldfile;
2539-
bool has_dirs = 0;
2538+
int restore_alias_len, global_flags = 0;
2539+
bool must_close_old_file = false;
2540+
bool has_dirs = false;
25402541
char manifest[18], entry_buffer[24];
25412542
zend_off_t manifest_ftell;
25422543
zend_long offset;
@@ -2547,8 +2548,9 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
25472548
php_stream_filter *filter;
25482549
php_serialize_data_t metadata_hash;
25492550
smart_str main_metadata_str = {0};
2550-
int free_fp = 1, free_ufp = 1;
2551-
int manifest_hack = 0;
2551+
bool free_fp = true;
2552+
bool free_ufp = true;
2553+
bool manifest_hack = false;
25522554
php_stream *shared_cfp = NULL;
25532555

25542556
if (phar->is_persistent) {
@@ -2582,18 +2584,18 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
25822584

25832585
if (phar->fp && !phar->is_brandnew) {
25842586
oldfile = phar->fp;
2585-
closeoldfile = 0;
2587+
must_close_old_file = false;
25862588
php_stream_rewind(oldfile);
25872589
} else {
25882590
oldfile = php_stream_open_wrapper(phar->fname, "rb", 0, NULL);
2589-
closeoldfile = oldfile != NULL;
2591+
must_close_old_file = oldfile != NULL;
25902592
}
25912593
newfile = php_stream_fopen_tmpfile();
25922594
if (!newfile) {
25932595
if (error) {
25942596
spprintf(error, 0, "unable to create temporary file");
25952597
}
2596-
if (closeoldfile) {
2598+
if (must_close_old_file) {
25972599
php_stream_close(oldfile);
25982600
}
25992601
return EOF;
@@ -2603,7 +2605,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
26032605
char *pos = php_stristr(ZSTR_VAL(user_stub), halt_stub, ZSTR_LEN(user_stub), strlen(halt_stub));
26042606

26052607
if (pos == NULL) {
2606-
if (closeoldfile) {
2608+
if (must_close_old_file) {
26072609
php_stream_close(oldfile);
26082610
}
26092611
php_stream_close(newfile);
@@ -2621,7 +2623,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
26212623
len != php_stream_write(newfile, ZSTR_VAL(user_stub), len)
26222624
|| end_sequence_len != php_stream_write(newfile, end_sequence, end_sequence_len)
26232625
) {
2624-
if (closeoldfile) {
2626+
if (must_close_old_file) {
26252627
php_stream_close(oldfile);
26262628
}
26272629
php_stream_close(newfile);
@@ -2644,7 +2646,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
26442646
written = php_stream_write(newfile, ZSTR_VAL(newstub), phar->halt_offset);
26452647
}
26462648
if (phar->halt_offset != written) {
2647-
if (closeoldfile) {
2649+
if (must_close_old_file) {
26482650
php_stream_close(oldfile);
26492651
}
26502652
php_stream_close(newfile);
@@ -2697,10 +2699,10 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
26972699
/* open file pointers refer to this fp, do not free the stream */
26982700
switch (entry->fp_type) {
26992701
case PHAR_FP:
2700-
free_fp = 0;
2702+
free_fp = false;
27012703
break;
27022704
case PHAR_UFP:
2703-
free_ufp = 0;
2705+
free_ufp = false;
27042706
default:
27052707
break;
27062708
}
@@ -2711,7 +2713,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
27112713

27122714
if (entry->is_dir) {
27132715
/* we use this to calculate API version, 1.1.1 is used for phars with directories */
2714-
has_dirs = 1;
2716+
has_dirs = true;
27152717
}
27162718
if (!Z_ISUNDEF(entry->metadata_tracker.val) && !entry->metadata_tracker.str) {
27172719
ZEND_ASSERT(!entry->is_persistent);
@@ -2747,7 +2749,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
27472749
}
27482750
file = phar_get_efp(entry, 0);
27492751
if (-1 == phar_seek_efp(entry, 0, SEEK_SET, 0, 1)) {
2750-
if (closeoldfile) {
2752+
if (must_close_old_file) {
27512753
php_stream_close(oldfile);
27522754
}
27532755
php_stream_close(newfile);
@@ -2767,7 +2769,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
27672769
}
27682770
filter = php_stream_filter_create(phar_compress_filter(entry, 0), NULL, 0);
27692771
if (!filter) {
2770-
if (closeoldfile) {
2772+
if (must_close_old_file) {
27712773
php_stream_close(oldfile);
27722774
}
27732775
php_stream_close(newfile);
@@ -2794,7 +2796,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
27942796
if (error) {
27952797
spprintf(error, 0, "unable to create temporary file");
27962798
}
2797-
if (closeoldfile) {
2799+
if (must_close_old_file) {
27982800
php_stream_close(oldfile);
27992801
}
28002802
php_stream_close(newfile);
@@ -2805,7 +2807,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
28052807
entry->header_offset = php_stream_tell(entry->cfp);
28062808
php_stream_flush(file);
28072809
if (-1 == phar_seek_efp(entry, 0, SEEK_SET, 0, 0)) {
2808-
if (closeoldfile) {
2810+
if (must_close_old_file) {
28092811
php_stream_close(oldfile);
28102812
}
28112813
php_stream_close(newfile);
@@ -2816,7 +2818,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
28162818
}
28172819
php_stream_filter_append((&entry->cfp->writefilters), filter);
28182820
if (SUCCESS != php_stream_copy_to_stream_ex(file, entry->cfp, entry->uncompressed_filesize, NULL)) {
2819-
if (closeoldfile) {
2821+
if (must_close_old_file) {
28202822
php_stream_close(oldfile);
28212823
}
28222824
php_stream_close(newfile);
@@ -2858,7 +2860,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
28582860
if(manifest[0] == '\r' || manifest[0] == '\n') {
28592861
manifest_len++;
28602862
phar_set_32(manifest, manifest_len);
2861-
manifest_hack = 1;
2863+
manifest_hack = true;
28622864
}
28632865
phar_set_32(manifest+4, new_manifest_count);
28642866
if (has_dirs) {
@@ -2875,7 +2877,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
28752877
if (sizeof(manifest) != php_stream_write(newfile, manifest, sizeof(manifest))
28762878
|| (size_t)phar->alias_len != php_stream_write(newfile, phar->alias, phar->alias_len)) {
28772879

2878-
if (closeoldfile) {
2880+
if (must_close_old_file) {
28792881
php_stream_close(oldfile);
28802882
}
28812883

@@ -2896,7 +2898,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
28962898
&& ZSTR_LEN(main_metadata_str.s) != php_stream_write(newfile, ZSTR_VAL(main_metadata_str.s), ZSTR_LEN(main_metadata_str.s)))) {
28972899
smart_str_free(&main_metadata_str);
28982900

2899-
if (closeoldfile) {
2901+
if (must_close_old_file) {
29002902
php_stream_close(oldfile);
29012903
}
29022904

@@ -2932,7 +2934,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
29322934
if (4 != php_stream_write(newfile, entry_buffer, 4)
29332935
|| entry->filename_len != php_stream_write(newfile, entry->filename, entry->filename_len)
29342936
|| (entry->is_dir && 1 != php_stream_write(newfile, "/", 1))) {
2935-
if (closeoldfile) {
2937+
if (must_close_old_file) {
29362938
php_stream_close(oldfile);
29372939
}
29382940
php_stream_close(newfile);
@@ -2967,7 +2969,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
29672969
if (sizeof(entry_buffer) != php_stream_write(newfile, entry_buffer, sizeof(entry_buffer))
29682970
|| (metadata_str &&
29692971
ZSTR_LEN(metadata_str) != php_stream_write(newfile, ZSTR_VAL(metadata_str), ZSTR_LEN(metadata_str)))) {
2970-
if (closeoldfile) {
2972+
if (must_close_old_file) {
29712973
php_stream_close(oldfile);
29722974
}
29732975

@@ -2981,9 +2983,9 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
29812983
}
29822984
} ZEND_HASH_FOREACH_END();
29832985
/* Hack - see bug #65028, add padding byte to the end of the manifest */
2984-
if(manifest_hack) {
2986+
if (manifest_hack) {
29852987
if(1 != php_stream_write(newfile, manifest, 1)) {
2986-
if (closeoldfile) {
2988+
if (must_close_old_file) {
29872989
php_stream_close(oldfile);
29882990
}
29892991

@@ -3010,7 +3012,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
30103012
} else {
30113013
file = phar_get_efp(entry, 0);
30123014
if (-1 == phar_seek_efp(entry, 0, SEEK_SET, 0, 0)) {
3013-
if (closeoldfile) {
3015+
if (must_close_old_file) {
30143016
php_stream_close(oldfile);
30153017
}
30163018
php_stream_close(newfile);
@@ -3022,7 +3024,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
30223024
}
30233025

30243026
if (!file) {
3025-
if (closeoldfile) {
3027+
if (must_close_old_file) {
30263028
php_stream_close(oldfile);
30273029
}
30283030
php_stream_close(newfile);
@@ -3036,7 +3038,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
30363038
entry->offset = entry->offset_abs = offset;
30373039
offset += entry->compressed_filesize;
30383040
if (php_stream_copy_to_stream_ex(file, newfile, entry->compressed_filesize, &wrote) == FAILURE) {
3039-
if (closeoldfile) {
3041+
if (must_close_old_file) {
30403042
php_stream_close(oldfile);
30413043
}
30423044

@@ -3099,7 +3101,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
30993101
if (digest) {
31003102
efree(digest);
31013103
}
3102-
if (closeoldfile) {
3104+
if (must_close_old_file) {
31033105
php_stream_close(oldfile);
31043106
}
31053107
php_stream_close(newfile);
@@ -3136,7 +3138,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
31363138
phar->ufp = NULL;
31373139
}
31383140

3139-
if (closeoldfile) {
3141+
if (must_close_old_file) {
31403142
php_stream_close(oldfile);
31413143
}
31423144

ext/phar/tar.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ int phar_tar_flush(phar_archive_data *phar, zend_string *user_stub, bool is_defa
960960
phar_entry_info entry = {0};
961961
static const char newstub[] = "<?php // tar-based phar archive stub file\n__HALT_COMPILER();";
962962
php_stream *oldfile, *newfile;
963-
int closeoldfile;
963+
bool must_close_old_file = false;
964964
size_t signature_length;
965965
struct _phar_pass_tar_info pass;
966966
char *buf, *signature, sigbuf[8];
@@ -1092,19 +1092,19 @@ int phar_tar_flush(phar_archive_data *phar, zend_string *user_stub, bool is_defa
10921092
nostub:
10931093
if (phar->fp && !phar->is_brandnew) {
10941094
oldfile = phar->fp;
1095-
closeoldfile = 0;
1095+
must_close_old_file = false;
10961096
php_stream_rewind(oldfile);
10971097
} else {
10981098
oldfile = php_stream_open_wrapper(phar->fname, "rb", 0, NULL);
1099-
closeoldfile = oldfile != NULL;
1099+
must_close_old_file = oldfile != NULL;
11001100
}
11011101

11021102
newfile = php_stream_fopen_tmpfile();
11031103
if (!newfile) {
11041104
if (error) {
11051105
spprintf(error, 0, "unable to create temporary file");
11061106
}
1107-
if (closeoldfile) {
1107+
if (must_close_old_file) {
11081108
php_stream_close(oldfile);
11091109
}
11101110
return EOF;
@@ -1120,7 +1120,7 @@ int phar_tar_flush(phar_archive_data *phar, zend_string *user_stub, bool is_defa
11201120
phar_entry_info *mentry;
11211121
if (NULL != (mentry = zend_hash_str_find_ptr(&(phar->manifest), ".phar/.metadata.bin", sizeof(".phar/.metadata.bin")-1))) {
11221122
if (ZEND_HASH_APPLY_KEEP != phar_tar_setmetadata(&phar->metadata_tracker, mentry, error)) {
1123-
if (closeoldfile) {
1123+
if (must_close_old_file) {
11241124
php_stream_close(oldfile);
11251125
}
11261126
return EOF;
@@ -1136,15 +1136,15 @@ int phar_tar_flush(phar_archive_data *phar, zend_string *user_stub, bool is_defa
11361136

11371137
if (NULL == (mentry = zend_hash_str_add_mem(&(phar->manifest), ".phar/.metadata.bin", sizeof(".phar/.metadata.bin")-1, (void *)&newentry, sizeof(phar_entry_info)))) {
11381138
spprintf(error, 0, "phar tar error: unable to add magic metadata file to manifest for phar archive \"%s\"", phar->fname);
1139-
if (closeoldfile) {
1139+
if (must_close_old_file) {
11401140
php_stream_close(oldfile);
11411141
}
11421142
return EOF;
11431143
}
11441144

11451145
if (ZEND_HASH_APPLY_KEEP != phar_tar_setmetadata(&phar->metadata_tracker, mentry, error)) {
11461146
zend_hash_str_del(&(phar->manifest), ".phar/.metadata.bin", sizeof(".phar/.metadata.bin")-1);
1147-
if (closeoldfile) {
1147+
if (must_close_old_file) {
11481148
php_stream_close(oldfile);
11491149
}
11501150
return EOF;
@@ -1155,7 +1155,7 @@ int phar_tar_flush(phar_archive_data *phar, zend_string *user_stub, bool is_defa
11551155
zend_hash_apply_with_argument(&phar->manifest, phar_tar_setupmetadata, (void *) &pass);
11561156

11571157
if (error && *error) {
1158-
if (closeoldfile) {
1158+
if (must_close_old_file) {
11591159
php_stream_close(oldfile);
11601160
}
11611161

@@ -1175,7 +1175,7 @@ int phar_tar_flush(phar_archive_data *phar, zend_string *user_stub, bool is_defa
11751175
efree(save);
11761176
}
11771177

1178-
if (closeoldfile) {
1178+
if (must_close_old_file) {
11791179
php_stream_close(oldfile);
11801180
}
11811181

@@ -1210,7 +1210,7 @@ int phar_tar_flush(phar_archive_data *phar, zend_string *user_stub, bool is_defa
12101210
spprintf(error, 0, "phar error: unable to write signature to tar-based phar %s", phar->fname);
12111211
}
12121212

1213-
if (closeoldfile) {
1213+
if (must_close_old_file) {
12141214
php_stream_close(oldfile);
12151215
}
12161216
php_stream_close(newfile);
@@ -1223,7 +1223,7 @@ int phar_tar_flush(phar_archive_data *phar, zend_string *user_stub, bool is_defa
12231223
entry.filename_len = phar_tar_writeheaders_int(&entry, (void *)&pass);
12241224

12251225
if (error && *error) {
1226-
if (closeoldfile) {
1226+
if (must_close_old_file) {
12271227
php_stream_close(oldfile);
12281228
}
12291229
/* error is set by writeheaders */
@@ -1237,7 +1237,7 @@ int phar_tar_flush(phar_archive_data *phar, zend_string *user_stub, bool is_defa
12371237
php_stream_write(newfile, buf, 1024);
12381238
efree(buf);
12391239

1240-
if (closeoldfile) {
1240+
if (must_close_old_file) {
12411241
php_stream_close(oldfile);
12421242
}
12431243

0 commit comments

Comments
 (0)