mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
sapi/fpm: remove use of variable-length arrays (#10645)
According to @cmb69, PHP does not require VLA support (https://github.com/php/php-src/pull/10304#discussion_r1069343092). VLAs are a bad idea for several reasons, so let's get rid of them. Two of the VLAs were probably unintended; unlike C++, C doesn't have the concept of "constant expressions", so an array with a "const" length is technically still a VLA. This is fixed by removing the "const" variable, and using sizeof() instead.
This commit is contained in:
@@ -39,15 +39,14 @@ static int fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{ *
|
||||
int callers_limit = child->wp->config->request_slowlog_trace_depth;
|
||||
pid_t pid = child->pid;
|
||||
struct timeval tv;
|
||||
static const int buf_size = 1024;
|
||||
char buf[buf_size];
|
||||
char buf[1024];
|
||||
long execute_data;
|
||||
long path_translated;
|
||||
long l;
|
||||
|
||||
gettimeofday(&tv, 0);
|
||||
|
||||
zlog_print_time(&tv, buf, buf_size);
|
||||
zlog_print_time(&tv, buf, sizeof(buf));
|
||||
|
||||
fprintf(slowlog, "\n%s [pool %s] pid %d\n", buf, child->wp->config->name, (int) pid);
|
||||
|
||||
@@ -57,7 +56,7 @@ static int fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{ *
|
||||
|
||||
path_translated = l;
|
||||
|
||||
if (0 > fpm_trace_get_strz(buf, buf_size, path_translated)) {
|
||||
if (0 > fpm_trace_get_strz(buf, sizeof(buf), path_translated)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -103,7 +102,7 @@ static int fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{ *
|
||||
ZEND_UNREACHABLE();
|
||||
}
|
||||
} else {
|
||||
if (0 > fpm_trace_get_strz(buf, buf_size, function_name + offsetof(zend_string, val))) {
|
||||
if (0 > fpm_trace_get_strz(buf, sizeof(buf), function_name + offsetof(zend_string, val))) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -149,7 +148,7 @@ static int fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{ *
|
||||
|
||||
file_name = l;
|
||||
|
||||
if (0 > fpm_trace_get_strz(buf, buf_size, file_name + offsetof(zend_string, val))) {
|
||||
if (0 > fpm_trace_get_strz(buf, sizeof(buf), file_name + offsetof(zend_string, val))) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -168,9 +168,8 @@ int fpm_stdio_flush_child(void)
|
||||
|
||||
static void fpm_stdio_child_said(struct fpm_event_s *ev, short which, void *arg) /* {{{ */
|
||||
{
|
||||
static const int max_buf_size = 1024;
|
||||
int fd = ev->fd;
|
||||
char buf[max_buf_size];
|
||||
char buf[1024];
|
||||
struct fpm_child_s *child;
|
||||
int is_stdout;
|
||||
struct fpm_event_s *event;
|
||||
@@ -219,7 +218,7 @@ static void fpm_stdio_child_said(struct fpm_event_s *ev, short which, void *arg)
|
||||
|
||||
while (1) {
|
||||
stdio_read:
|
||||
in_buf = read(fd, buf, max_buf_size - 1);
|
||||
in_buf = read(fd, buf, sizeof(buf) - 1);
|
||||
if (in_buf <= 0) { /* no data */
|
||||
if (in_buf == 0 || !PHP_IS_TRANSIENT_ERROR(errno)) {
|
||||
/* pipe is closed or error */
|
||||
|
||||
Reference in New Issue
Block a user