Skip to content

Commit a112c2d

Browse files
committed
Use size_t for array indexes
1 parent 19fcda2 commit a112c2d

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

ext/standard/proc_open.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ static void proc_open_rsrc_dtor(zend_resource *rsrc)
241241
#endif
242242

243243
/* Close all handles to avoid a deadlock */
244-
for (int i = 0; i < proc->npipes; i++) {
244+
for (size_t i = 0; i < proc->npipes; i++) {
245245
if (proc->pipes[i] != NULL) {
246246
GC_DELREF(proc->pipes[i]);
247247
zend_list_close(proc->pipes[i]);
@@ -557,7 +557,7 @@ static int get_option(zval *other_options, char *opt_name)
557557

558558
/* Initialize STARTUPINFOW struct, used on Windows when spawning a process.
559559
* Ref: https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/ns-processthreadsapi-startupinfow */
560-
static void init_startup_info(STARTUPINFOW *si, descriptorspec_item *descriptors, int ndesc)
560+
static void init_startup_info(STARTUPINFOW *si, descriptorspec_item *descriptors, size_t ndesc)
561561
{
562562
memset(si, 0, sizeof(STARTUPINFOW));
563563
si->cb = sizeof(STARTUPINFOW);
@@ -568,7 +568,7 @@ static void init_startup_info(STARTUPINFOW *si, descriptorspec_item *descriptors
568568
si->hStdError = GetStdHandle(STD_ERROR_HANDLE);
569569

570570
/* redirect stdin/stdout/stderr if requested */
571-
for (int i = 0; i < ndesc; i++) {
571+
for (size_t i = 0; i < ndesc; i++) {
572572
switch (descriptors[i].index) {
573573
case 0:
574574
si->hStdInput = descriptors[i].childend;
@@ -612,11 +612,11 @@ static int convert_command_to_use_shell(wchar_t **cmdw, size_t cmdw_len)
612612
#endif
613613

614614
/* Convert command parameter array passed as first argument to `proc_open` into command string */
615-
static zend_string* get_command_from_array(HashTable *array, char ***argv, int num_elems)
615+
static zend_string* get_command_from_array(HashTable *array, char ***argv, uint32_t num_elems)
616616
{
617617
zval *arg_zv;
618618
zend_string *command = NULL;
619-
int i = 0;
619+
size_t i = 0;
620620

621621
*argv = safe_emalloc(sizeof(char *), num_elems + 1, 0);
622622

@@ -645,7 +645,7 @@ static zend_string* get_command_from_array(HashTable *array, char ***argv, int n
645645

646646
static descriptorspec_item* alloc_descriptor_array(zval *descriptorspec)
647647
{
648-
int ndescriptors = zend_hash_num_elements(Z_ARRVAL_P(descriptorspec));
648+
uint32_t ndescriptors = zend_hash_num_elements(Z_ARRVAL_P(descriptorspec));
649649
return ecalloc(sizeof(descriptorspec_item), ndescriptors);
650650
}
651651

@@ -808,18 +808,18 @@ static int set_proc_descriptor_to_file(descriptorspec_item *desc, zend_string *f
808808
}
809809

810810
static int dup_proc_descriptor(php_file_descriptor_t from, php_file_descriptor_t *to,
811-
zend_ulong nindex)
811+
size_t nindex)
812812
{
813813
#ifdef PHP_WIN32
814814
*to = dup_handle(from, TRUE, FALSE);
815815
if (*to == NULL) {
816-
php_error_docref(NULL, E_WARNING, "Failed to dup() for descriptor " ZEND_LONG_FMT, nindex);
816+
php_error_docref(NULL, E_WARNING, "Failed to dup() for descriptor %zu", nindex);
817817
return FAILURE;
818818
}
819819
#else
820820
*to = dup(from);
821821
if (*to < 0) {
822-
php_error_docref(NULL, E_WARNING, "Failed to dup() for descriptor " ZEND_LONG_FMT ": %s",
822+
php_error_docref(NULL, E_WARNING, "Failed to dup() for descriptor %zu: %s",
823823
nindex, strerror(errno));
824824
return FAILURE;
825825
}
@@ -828,11 +828,11 @@ static int dup_proc_descriptor(php_file_descriptor_t from, php_file_descriptor_t
828828
}
829829

830830
static int redirect_proc_descriptor(descriptorspec_item *desc, int target,
831-
descriptorspec_item *descriptors, int ndesc, int nindex)
831+
descriptorspec_item *descriptors, size_t ndesc, size_t nindex)
832832
{
833833
php_file_descriptor_t redirect_to = PHP_INVALID_FD;
834834

835-
for (int i = 0; i < ndesc; i++) {
835+
for (size_t i = 0; i < ndesc; i++) {
836836
if (descriptors[i].index == target) {
837837
redirect_to = descriptors[i].childend;
838838
break;
@@ -864,7 +864,7 @@ static int redirect_proc_descriptor(descriptorspec_item *desc, int target,
864864

865865
/* Process one item from `$descriptorspec` argument to `proc_open` */
866866
static int set_proc_descriptor_from_array(zval *descitem, descriptorspec_item *descriptors,
867-
int ndesc, int nindex, int *pty_master_fd, int *pty_slave_fd) {
867+
size_t ndesc, size_t nindex, int *pty_master_fd, int *pty_slave_fd) {
868868
zend_string *ztype = get_string_parameter(descitem, 0, "handle qualifier");
869869
if (!ztype) {
870870
return FAILURE;
@@ -923,7 +923,7 @@ static int set_proc_descriptor_from_array(zval *descitem, descriptorspec_item *d
923923
return retval;
924924
}
925925

926-
static int set_proc_descriptor_from_resource(zval *resource, descriptorspec_item *desc, int nindex)
926+
static int set_proc_descriptor_from_resource(zval *resource, descriptorspec_item *desc, size_t nindex)
927927
{
928928
/* Should be a stream - try and dup the descriptor */
929929
php_stream *stream = (php_stream*)zend_fetch_resource(Z_RES_P(resource), "stream",
@@ -951,13 +951,13 @@ static int set_proc_descriptor_from_resource(zval *resource, descriptorspec_item
951951
}
952952

953953
#ifndef PHP_WIN32
954-
static int close_parentends_of_pipes(descriptorspec_item *descriptors, int ndesc)
954+
static int close_parentends_of_pipes(descriptorspec_item *descriptors, size_t ndesc)
955955
{
956956
/* We are running in child process
957957
* Close the 'parent end' of pipes which were opened before forking/spawning
958958
* Also, dup() the child end of all pipes as necessary so they will use the FD
959959
* number which the user requested */
960-
for (int i = 0; i < ndesc; i++) {
960+
for (size_t i = 0; i < ndesc; i++) {
961961
if (descriptors[i].type != DESCRIPTOR_TYPE_STD) {
962962
close(descriptors[i].parentend);
963963
}
@@ -975,9 +975,9 @@ static int close_parentends_of_pipes(descriptorspec_item *descriptors, int ndesc
975975
}
976976
#endif
977977

978-
static void close_all_descriptors(descriptorspec_item *descriptors, int ndesc)
978+
static void close_all_descriptors(descriptorspec_item *descriptors, size_t ndesc)
979979
{
980-
for (int i = 0; i < ndesc; i++) {
980+
for (size_t i = 0; i < ndesc; i++) {
981981
close_descriptor(descriptors[i].childend);
982982
if (descriptors[i].parentend)
983983
close_descriptor(descriptors[i].parentend);
@@ -1007,8 +1007,8 @@ PHP_FUNCTION(proc_open)
10071007
zval *environment = NULL, *other_options = NULL; /* Optional arguments */
10081008

10091009
php_process_env env;
1010-
int ndesc = 0;
1011-
int i;
1010+
size_t ndesc = 0;
1011+
size_t i;
10121012
zval *descitem = NULL;
10131013
zend_string *str_index;
10141014
zend_ulong nindex;
@@ -1093,14 +1093,14 @@ PHP_FUNCTION(proc_open)
10931093
goto exit_fail;
10941094
}
10951095

1096-
descriptors[ndesc].index = (int)nindex;
1096+
descriptors[ndesc].index = nindex;
10971097

10981098
if (Z_TYPE_P(descitem) == IS_RESOURCE) {
10991099
if (set_proc_descriptor_from_resource(descitem, &descriptors[ndesc], ndesc) == FAILURE) {
11001100
goto exit_fail;
11011101
}
11021102
} else if (Z_TYPE_P(descitem) == IS_ARRAY) {
1103-
if (set_proc_descriptor_from_array(descitem, descriptors, ndesc, (int)nindex,
1103+
if (set_proc_descriptor_from_array(descitem, descriptors, ndesc, nindex,
11041104
&pty_master_fd, &pty_slave_fd) == FAILURE) {
11051105
goto exit_fail;
11061106
}

ext/standard/proc_open.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ typedef struct _php_process_handle {
3939
#ifdef PHP_WIN32
4040
HANDLE childHandle;
4141
#endif
42-
int npipes;
42+
size_t npipes;
4343
zend_resource **pipes;
4444
char *command;
4545
php_process_env env;

0 commit comments

Comments
 (0)