Skip to content

Commit ff2a211

Browse files
sapi/fpm: remove use of variable-length arrays (#10645)
According to @cmb69, PHP does not require VLA support (#10304 (comment)). 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.
1 parent bb07e20 commit ff2a211

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

sapi/fpm/fpm/fpm_php_trace.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,14 @@ static int fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{ *
3939
int callers_limit = child->wp->config->request_slowlog_trace_depth;
4040
pid_t pid = child->pid;
4141
struct timeval tv;
42-
static const int buf_size = 1024;
43-
char buf[buf_size];
42+
char buf[1024];
4443
long execute_data;
4544
long path_translated;
4645
long l;
4746

4847
gettimeofday(&tv, 0);
4948

50-
zlog_print_time(&tv, buf, buf_size);
49+
zlog_print_time(&tv, buf, sizeof(buf));
5150

5251
fprintf(slowlog, "\n%s [pool %s] pid %d\n", buf, child->wp->config->name, (int) pid);
5352

@@ -57,7 +56,7 @@ static int fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{ *
5756

5857
path_translated = l;
5958

60-
if (0 > fpm_trace_get_strz(buf, buf_size, path_translated)) {
59+
if (0 > fpm_trace_get_strz(buf, sizeof(buf), path_translated)) {
6160
return -1;
6261
}
6362

@@ -103,7 +102,7 @@ static int fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{ *
103102
ZEND_UNREACHABLE();
104103
}
105104
} else {
106-
if (0 > fpm_trace_get_strz(buf, buf_size, function_name + offsetof(zend_string, val))) {
105+
if (0 > fpm_trace_get_strz(buf, sizeof(buf), function_name + offsetof(zend_string, val))) {
107106
return -1;
108107
}
109108

@@ -149,7 +148,7 @@ static int fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{ *
149148

150149
file_name = l;
151150

152-
if (0 > fpm_trace_get_strz(buf, buf_size, file_name + offsetof(zend_string, val))) {
151+
if (0 > fpm_trace_get_strz(buf, sizeof(buf), file_name + offsetof(zend_string, val))) {
153152
return -1;
154153
}
155154

sapi/fpm/fpm/fpm_stdio.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,8 @@ int fpm_stdio_flush_child(void)
168168

169169
static void fpm_stdio_child_said(struct fpm_event_s *ev, short which, void *arg) /* {{{ */
170170
{
171-
static const int max_buf_size = 1024;
172171
int fd = ev->fd;
173-
char buf[max_buf_size];
172+
char buf[1024];
174173
struct fpm_child_s *child;
175174
int is_stdout;
176175
struct fpm_event_s *event;
@@ -219,7 +218,7 @@ static void fpm_stdio_child_said(struct fpm_event_s *ev, short which, void *arg)
219218

220219
while (1) {
221220
stdio_read:
222-
in_buf = read(fd, buf, max_buf_size - 1);
221+
in_buf = read(fd, buf, sizeof(buf) - 1);
223222
if (in_buf <= 0) { /* no data */
224223
if (in_buf == 0 || !PHP_IS_TRANSIENT_ERROR(errno)) {
225224
/* pipe is closed or error */

0 commit comments

Comments
 (0)