Skip to content

Commit 73ecac8

Browse files
committed
fix datatype mismatches and warnings
1 parent b983929 commit 73ecac8

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

main/main.c

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ static PHP_INI_MH(OnSetPrecision)
178178
static PHP_INI_MH(OnChangeMemoryLimit)
179179
{
180180
if (new_value) {
181-
PG(memory_limit) = zend_atol(new_value->val, new_value->len);
181+
PG(memory_limit) = zend_atol(new_value->val, (int)new_value->len);
182182
} else {
183183
PG(memory_limit) = 1<<30; /* effectively, no limit */
184184
}
@@ -364,7 +364,7 @@ static int php_get_display_errors_mode(char *value, int value_length)
364364
*/
365365
static PHP_INI_MH(OnUpdateDisplayErrors)
366366
{
367-
PG(display_errors) = (zend_bool) php_get_display_errors_mode(new_value->val, new_value->len);
367+
PG(display_errors) = (zend_bool) php_get_display_errors_mode(new_value->val, (int)new_value->len);
368368

369369
return SUCCESS;
370370
}
@@ -380,10 +380,10 @@ static PHP_INI_DISP(display_errors_mode)
380380

381381
if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {
382382
tmp_value = (ini_entry->orig_value ? ini_entry->orig_value->val : NULL );
383-
tmp_value_length = ini_entry->orig_value->len;
383+
tmp_value_length = (int)ini_entry->orig_value->len;
384384
} else if (ini_entry->value) {
385385
tmp_value = ini_entry->value->val;
386-
tmp_value_length = ini_entry->value->len;
386+
tmp_value_length = (int)ini_entry->value->len;
387387
} else {
388388
tmp_value = NULL;
389389
tmp_value_length = 0;
@@ -672,7 +672,7 @@ PHPAPI void php_log_err(char *log_message TSRMLS_DC)
672672
fd = VCWD_OPEN_MODE(PG(error_log), O_CREAT | O_APPEND | O_WRONLY, 0644);
673673
if (fd != -1) {
674674
char *tmp;
675-
int len;
675+
size_t len;
676676
zend_string *error_time_str;
677677

678678
time(&error_time);
@@ -688,8 +688,11 @@ PHPAPI void php_log_err(char *log_message TSRMLS_DC)
688688
len = spprintf(&tmp, 0, "[%s] %s%s", error_time_str->val, log_message, PHP_EOL);
689689
#ifdef PHP_WIN32
690690
php_flock(fd, 2);
691-
#endif
691+
/* XXX should eventually write in a loop if len > UINT_MAX */
692+
php_ignore_value(write(fd, tmp, (unsigned)len));
693+
#else
692694
php_ignore_value(write(fd, tmp, len));
695+
#endif
693696
efree(tmp);
694697
zend_string_free(error_time_str);
695698
close(fd);
@@ -757,13 +760,13 @@ PHPAPI void php_verror(const char *docref, const char *params, int type, const c
757760
int is_function = 0;
758761

759762
/* get error text into buffer and escape for html if necessary */
760-
buffer_len = vspprintf(&buffer, 0, format, args);
763+
buffer_len = (int)vspprintf(&buffer, 0, format, args);
761764

762765
if (PG(html_errors)) {
763766
replace_buffer = php_escape_html_entities(buffer, buffer_len, 0, ENT_COMPAT, NULL TSRMLS_CC);
764767
efree(buffer);
765768
buffer = replace_buffer->val;
766-
buffer_len = replace_buffer->len;
769+
buffer_len = (int)replace_buffer->len;
767770
}
768771

769772
/* which function caused the problem if any at all */
@@ -813,9 +816,9 @@ PHPAPI void php_verror(const char *docref, const char *params, int type, const c
813816

814817
/* if we still have memory then format the origin */
815818
if (is_function) {
816-
origin_len = spprintf(&origin, 0, "%s%s%s(%s)", class_name, space, function, params);
819+
origin_len = (int)spprintf(&origin, 0, "%s%s%s(%s)", class_name, space, function, params);
817820
} else {
818-
origin_len = spprintf(&origin, 0, "%s", function);
821+
origin_len = (int)spprintf(&origin, 0, "%s", function);
819822
}
820823

821824
if (PG(html_errors)) {
@@ -837,9 +840,9 @@ PHPAPI void php_verror(const char *docref, const char *params, int type, const c
837840
function++;
838841
}
839842
if (space[0] == '\0') {
840-
doclen = spprintf(&docref_buf, 0, "function.%s", function);
843+
doclen = (int)spprintf(&docref_buf, 0, "function.%s", function);
841844
} else {
842-
doclen = spprintf(&docref_buf, 0, "%s.%s", class_name, function);
845+
doclen = (int)spprintf(&docref_buf, 0, "%s.%s", class_name, function);
843846
}
844847
while((p = strchr(docref_buf, '_')) != NULL) {
845848
*p = '-';
@@ -975,7 +978,7 @@ PHPAPI void php_win32_docref2_from_error(DWORD error, const char *param1, const
975978
int buf_len;
976979

977980
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, 0, buf, PHP_WIN32_ERROR_MSG_BUFFER_SIZE, NULL);
978-
buf_len = strlen(buf);
981+
buf_len = (int)strlen(buf);
979982
if (buf_len >= 2) {
980983
buf[buf_len - 1] = '\0';
981984
buf[buf_len - 2] = '\0';
@@ -1001,7 +1004,7 @@ static void php_error_cb(int type, const char *error_filename, const uint error_
10011004
int buffer_len, display;
10021005
TSRMLS_FETCH();
10031006

1004-
buffer_len = vspprintf(&buffer, PG(log_errors_max_len), format, args);
1007+
buffer_len = (int)vspprintf(&buffer, PG(log_errors_max_len), format, args);
10051008

10061009
/* check for repeated errors to be ignored */
10071010
if (PG(ignore_repeated_errors) && PG(last_error_message)) {
@@ -1337,7 +1340,7 @@ PHP_FUNCTION(set_time_limit)
13371340
return;
13381341
}
13391342

1340-
new_timeout_strlen = zend_spprintf(&new_timeout_str, 0, ZEND_LONG_FMT, new_timeout);
1343+
new_timeout_strlen = (int)zend_spprintf(&new_timeout_str, 0, ZEND_LONG_FMT, new_timeout);
13411344

13421345
key = zend_string_init("max_execution_time", sizeof("max_execution_time")-1, 0);
13431346
if (zend_alter_ini_entry_chars_ex(key, new_timeout_str, new_timeout_strlen, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0 TSRMLS_CC) == SUCCESS) {
@@ -2526,7 +2529,7 @@ PHPAPI int php_execute_script(zend_file_handle *primary_file TSRMLS_DC)
25262529
int realfile_len;
25272530

25282531
if (expand_filepath(primary_file->filename, realfile TSRMLS_CC)) {
2529-
realfile_len = strlen(realfile);
2532+
realfile_len = (int)strlen(realfile);
25302533
zend_hash_str_add_empty_element(&EG(included_files), realfile, realfile_len);
25312534
primary_file->opened_path = estrndup(realfile, realfile_len);
25322535
}

0 commit comments

Comments
 (0)