Skip to content

Commit c81e48f

Browse files
committed
ext/phar: Use size_t for string lenghts
And remove useless casts
1 parent a736697 commit c81e48f

File tree

4 files changed

+24
-32
lines changed

4 files changed

+24
-32
lines changed

ext/phar/dirstream.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,6 @@ php_stream *phar_wrapper_open_dir(php_stream_wrapper *wrapper, const char *path,
295295
zend_ulong unused;
296296
phar_archive_data *phar;
297297
phar_entry_info *entry = NULL;
298-
uint32_t host_len;
299298

300299
if ((resource = phar_parse_url(wrapper, path, mode, options)) == NULL) {
301300
php_stream_wrapper_log_error(wrapper, options, "phar url \"%s\" is unknown", path);
@@ -320,7 +319,7 @@ php_stream *phar_wrapper_open_dir(php_stream_wrapper *wrapper, const char *path,
320319
return NULL;
321320
}
322321

323-
host_len = ZSTR_LEN(resource->host);
322+
size_t host_len = ZSTR_LEN(resource->host);
324323
phar_request_initialize();
325324
internal_file = ZSTR_VAL(resource->path) + 1; /* strip leading "/" */
326325

@@ -401,7 +400,6 @@ int phar_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url_from, int mo
401400
char *error, *arch, *entry2;
402401
size_t arch_len, entry_len;
403402
php_url *resource = NULL;
404-
uint32_t host_len;
405403

406404
/* pre-readonly check, we need to know if this is a data phar */
407405
if (FAILURE == phar_split_fname(url_from, strlen(url_from), &arch, &arch_len, &entry2, &entry_len, 2, 2)) {
@@ -438,7 +436,7 @@ int phar_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url_from, int mo
438436
return 0;
439437
}
440438

441-
host_len = ZSTR_LEN(resource->host);
439+
size_t host_len = ZSTR_LEN(resource->host);
442440

443441
if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(resource->host), host_len, NULL, 0, &error)) {
444442
php_stream_wrapper_log_error(wrapper, options, "phar error: cannot create directory \"%s\" in phar \"%s\", error retrieving phar information: %s", ZSTR_VAL(resource->path) + 1, ZSTR_VAL(resource->host), error);
@@ -533,10 +531,8 @@ int phar_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, int options
533531
char *error, *arch, *entry2;
534532
size_t arch_len, entry_len;
535533
php_url *resource = NULL;
536-
uint32_t host_len;
537534
zend_string *str_key;
538535
zend_ulong unused;
539-
uint32_t path_len;
540536

541537
/* pre-readonly check, we need to know if this is a data phar */
542538
if (FAILURE == phar_split_fname(url, strlen(url), &arch, &arch_len, &entry2, &entry_len, 2, 2)) {
@@ -573,7 +569,7 @@ int phar_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, int options
573569
return 0;
574570
}
575571

576-
host_len = ZSTR_LEN(resource->host);
572+
size_t host_len = ZSTR_LEN(resource->host);
577573

578574
if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(resource->host), host_len, NULL, 0, &error)) {
579575
php_stream_wrapper_log_error(wrapper, options, "phar error: cannot remove directory \"%s\" in phar \"%s\", error retrieving phar information: %s", ZSTR_VAL(resource->path)+1, ZSTR_VAL(resource->host), error);
@@ -582,7 +578,7 @@ int phar_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, int options
582578
return 0;
583579
}
584580

585-
path_len = ZSTR_LEN(resource->path) - 1;
581+
size_t path_len = ZSTR_LEN(resource->path) - 1;
586582

587583
if (!(entry = phar_get_entry_info_dir(phar, ZSTR_VAL(resource->path) + 1, path_len, 2, &error, 1))) {
588584
if (error) {

ext/phar/phar.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,11 +2023,11 @@ int phar_detect_phar_fname_ext(const char *filename, size_t filename_len, const
20232023
zend_string *str_key;
20242024

20252025
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&PHAR_G(phar_fname_map), str_key, pphar) {
2026-
if (ZSTR_LEN(str_key) > (uint32_t) filename_len) {
2026+
if (ZSTR_LEN(str_key) > filename_len) {
20272027
continue;
20282028
}
20292029

2030-
if (!memcmp(filename, ZSTR_VAL(str_key), ZSTR_LEN(str_key)) && ((uint32_t)filename_len == ZSTR_LEN(str_key)
2030+
if (!memcmp(filename, ZSTR_VAL(str_key), ZSTR_LEN(str_key)) && (filename_len == ZSTR_LEN(str_key)
20312031
|| filename[ZSTR_LEN(str_key)] == '/' || filename[ZSTR_LEN(str_key)] == '\0')) {
20322032
*ext_str = filename + (ZSTR_LEN(str_key) - pphar->ext_len);
20332033
goto woohoo;
@@ -2036,11 +2036,11 @@ int phar_detect_phar_fname_ext(const char *filename, size_t filename_len, const
20362036

20372037
if (PHAR_G(manifest_cached)) {
20382038
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&cached_phars, str_key, pphar) {
2039-
if (ZSTR_LEN(str_key) > (uint32_t) filename_len) {
2039+
if (ZSTR_LEN(str_key) > filename_len) {
20402040
continue;
20412041
}
20422042

2043-
if (!memcmp(filename, ZSTR_VAL(str_key), ZSTR_LEN(str_key)) && ((uint32_t)filename_len == ZSTR_LEN(str_key)
2043+
if (!memcmp(filename, ZSTR_VAL(str_key), ZSTR_LEN(str_key)) && (filename_len == ZSTR_LEN(str_key)
20442044
|| filename[ZSTR_LEN(str_key)] == '/' || filename[ZSTR_LEN(str_key)] == '\0')) {
20452045
*ext_str = filename + (ZSTR_LEN(str_key) - pphar->ext_len);
20462046
goto woohoo;

ext/phar/phar_object.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2621,7 +2621,7 @@ PHP_METHOD(Phar, delete)
26212621
zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%s\" is persistent, unable to copy on write", phar_obj->archive->fname);
26222622
RETURN_THROWS();
26232623
}
2624-
if (NULL != (entry = zend_hash_str_find_ptr(&phar_obj->archive->manifest, fname, (uint32_t) fname_len))) {
2624+
if (NULL != (entry = zend_hash_str_find_ptr(&phar_obj->archive->manifest, fname, fname_len))) {
26252625
if (entry->is_deleted) {
26262626
/* entry is deleted, but has not been flushed to disk yet */
26272627
RETURN_TRUE;
@@ -3440,13 +3440,13 @@ PHP_METHOD(Phar, copy)
34403440
RETURN_THROWS();
34413441
}
34423442

3443-
if (NULL == (oldentry = zend_hash_str_find_ptr(&phar_obj->archive->manifest, oldfile, (uint32_t) oldfile_len)) || oldentry->is_deleted) {
3443+
if (NULL == (oldentry = zend_hash_str_find_ptr(&phar_obj->archive->manifest, oldfile, oldfile_len)) || oldentry->is_deleted) {
34443444
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0,
34453445
"file \"%s\" cannot be copied to file \"%s\", file does not exist in %s", oldfile, newfile, phar_obj->archive->fname);
34463446
RETURN_THROWS();
34473447
}
34483448

3449-
if (NULL != (temp = zend_hash_str_find_ptr(&phar_obj->archive->manifest, newfile, (uint32_t) newfile_len)) && !temp->is_deleted) {
3449+
if (NULL != (temp = zend_hash_str_find_ptr(&phar_obj->archive->manifest, newfile, newfile_len)) && !temp->is_deleted) {
34503450
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0,
34513451
"file \"%s\" cannot be copied to file \"%s\", file must not already exist in phar %s", oldfile, newfile, phar_obj->archive->fname);
34523452
RETURN_THROWS();
@@ -3466,7 +3466,7 @@ PHP_METHOD(Phar, copy)
34663466
RETURN_THROWS();
34673467
}
34683468
/* re-populate with copied-on-write entry */
3469-
oldentry = zend_hash_str_find_ptr(&phar_obj->archive->manifest, oldfile, (uint32_t) oldfile_len);
3469+
oldentry = zend_hash_str_find_ptr(&phar_obj->archive->manifest, oldfile, oldfile_len);
34703470
}
34713471

34723472
memcpy((void *) &newentry, oldentry, sizeof(phar_entry_info));
@@ -3513,8 +3513,8 @@ PHP_METHOD(Phar, offsetExists)
35133513

35143514
PHAR_ARCHIVE_OBJECT();
35153515

3516-
if (zend_hash_str_exists(&phar_obj->archive->manifest, fname, (uint32_t) fname_len)) {
3517-
if (NULL != (entry = zend_hash_str_find_ptr(&phar_obj->archive->manifest, fname, (uint32_t) fname_len))) {
3516+
if (zend_hash_str_exists(&phar_obj->archive->manifest, fname, fname_len)) {
3517+
if (NULL != (entry = zend_hash_str_find_ptr(&phar_obj->archive->manifest, fname, fname_len))) {
35183518
if (entry->is_deleted) {
35193519
/* entry is deleted, but has not been flushed to disk yet */
35203520
RETURN_FALSE;
@@ -3527,7 +3527,7 @@ PHP_METHOD(Phar, offsetExists)
35273527
}
35283528
RETURN_TRUE;
35293529
} else {
3530-
if (zend_hash_str_exists(&phar_obj->archive->virtual_dirs, fname, (uint32_t) fname_len)) {
3530+
if (zend_hash_str_exists(&phar_obj->archive->virtual_dirs, fname, fname_len)) {
35313531
RETURN_TRUE;
35323532
}
35333533
RETURN_FALSE;
@@ -3772,8 +3772,8 @@ PHP_METHOD(Phar, offsetUnset)
37723772
RETURN_THROWS();
37733773
}
37743774

3775-
if (zend_hash_str_exists(&phar_obj->archive->manifest, fname, (uint32_t) fname_len)) {
3776-
if (NULL != (entry = zend_hash_str_find_ptr(&phar_obj->archive->manifest, fname, (uint32_t) fname_len))) {
3775+
if (zend_hash_str_exists(&phar_obj->archive->manifest, fname, fname_len)) {
3776+
if (NULL != (entry = zend_hash_str_find_ptr(&phar_obj->archive->manifest, fname, fname_len))) {
37773777
if (entry->is_deleted) {
37783778
/* entry is deleted, but has not been flushed to disk yet */
37793779
return;
@@ -3785,7 +3785,7 @@ PHP_METHOD(Phar, offsetUnset)
37853785
RETURN_THROWS();
37863786
}
37873787
/* re-populate entry after copy on write */
3788-
entry = zend_hash_str_find_ptr(&phar_obj->archive->manifest, fname, (uint32_t) fname_len);
3788+
entry = zend_hash_str_find_ptr(&phar_obj->archive->manifest, fname, fname_len);
37893789
}
37903790
entry->is_modified = 0;
37913791
entry->is_deleted = 1;

ext/phar/stream.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha
168168
php_url *resource = NULL;
169169
php_stream *fpf;
170170
zval *pzoption, *metadata;
171-
uint32_t host_len;
172171

173172
if ((resource = phar_parse_url(wrapper, path, mode, options)) == NULL) {
174173
return NULL;
@@ -187,7 +186,7 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha
187186
return NULL;
188187
}
189188

190-
host_len = ZSTR_LEN(resource->host);
189+
size_t host_len = ZSTR_LEN(resource->host);
191190
phar_request_initialize();
192191

193192
/* strip leading "/" */
@@ -565,7 +564,6 @@ static int phar_wrapper_stat(php_stream_wrapper *wrapper, const char *url, int f
565564
char *internal_file, *error;
566565
phar_archive_data *phar;
567566
phar_entry_info *entry;
568-
uint32_t host_len;
569567
size_t internal_file_len;
570568

571569
if ((resource = phar_parse_url(wrapper, url, "r", flags|PHP_STREAM_URL_STAT_QUIET)) == NULL) {
@@ -583,7 +581,7 @@ static int phar_wrapper_stat(php_stream_wrapper *wrapper, const char *url, int f
583581
return FAILURE;
584582
}
585583

586-
host_len = ZSTR_LEN(resource->host);
584+
size_t host_len = ZSTR_LEN(resource->host);
587585
phar_request_initialize();
588586

589587
internal_file = ZSTR_VAL(resource->path) + 1; /* strip leading "/" */
@@ -674,7 +672,6 @@ static int phar_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int
674672
int internal_file_len;
675673
phar_entry_data *idata;
676674
phar_archive_data *pphar;
677-
uint32_t host_len;
678675

679676
if ((resource = phar_parse_url(wrapper, url, "rb", options)) == NULL) {
680677
php_stream_wrapper_log_error(wrapper, options, "phar error: unlink failed");
@@ -694,7 +691,7 @@ static int phar_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int
694691
return 0;
695692
}
696693

697-
host_len = ZSTR_LEN(resource->host);
694+
size_t host_len = ZSTR_LEN(resource->host);
698695
phar_request_initialize();
699696

700697
pphar = zend_hash_find_ptr(&(PHAR_G(phar_fname_map)), resource->host);
@@ -747,7 +744,6 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from
747744
char *error;
748745
phar_archive_data *phar, *pfrom, *pto;
749746
phar_entry_info *entry;
750-
uint32_t host_len;
751747
int is_dir = 0;
752748
int is_modified = 0;
753749

@@ -823,7 +819,7 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from
823819
return 0;
824820
}
825821

826-
host_len = ZSTR_LEN(resource_from->host);
822+
size_t host_len = ZSTR_LEN(resource_from->host);
827823

828824
if (SUCCESS != phar_get_archive(&phar, ZSTR_VAL(resource_from->host), host_len, NULL, 0, &error)) {
829825
php_url_free(resource_from);
@@ -893,8 +889,8 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from
893889
Bucket *b;
894890
zend_string *str_key;
895891
zend_string *new_str_key;
896-
uint32_t from_len = ZSTR_LEN(resource_from->path) - 1;
897-
uint32_t to_len = ZSTR_LEN(resource_to->path) - 1;
892+
size_t from_len = ZSTR_LEN(resource_from->path) - 1;
893+
size_t to_len = ZSTR_LEN(resource_to->path) - 1;
898894

899895
ZEND_HASH_MAP_FOREACH_BUCKET(&phar->manifest, b) {
900896
str_key = b->key;

0 commit comments

Comments
 (0)