Skip to content

Commit

Permalink
Work around -Walloc-size-larger-than bug
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Apr 11, 2019
1 parent 7bb22df commit 09b2e20
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions sapi/phpdbg/phpdbg_eol.c
Expand Up @@ -81,27 +81,30 @@ char *phpdbg_eol_rep(int id)
return NULL;
}

/* Marked as never_inline to work around a -Walloc-size-larger-than bug in GCC. */
static zend_never_inline int count_lf_and_cr(const char *in, int in_len) {
int i, count = 0;
for (i = 0; i < in_len; i++) {
if (0x0a == in[i] || 0x0d == in[i]) {
count++;
}
}
return count;
}

/* Inspired by https://ccrma.stanford.edu/~craig/utility/flip/flip.cpp */
void phpdbg_eol_convert(char **str, int *len)
{
char *in = *str, *out ;
int in_len = *len, out_len, cursor, i;
char *in = *str, *out;
int in_len = *len, cursor, i;
char last, cur;

if ((PHPDBG_G(flags) & PHPDBG_IS_REMOTE) != PHPDBG_IS_REMOTE) {
return;
}

out_len = *len;
if (PHPDBG_EOL_CRLF == PHPDBG_G(eol)) { /* XXX add LFCR case if it's gonna be needed */
/* depending on the source EOL the out str will have all CR/LF duplicated */
for (i = 0; i < in_len; i++) {
if (0x0a == in[i] || 0x0d == in[i]) {
out_len++;
}
}
out = (char *)emalloc(out_len);
out = (char *)emalloc(in_len + count_lf_and_cr(in, in_len));

last = cur = in[0];
i = cursor = 0;
Expand Down Expand Up @@ -142,7 +145,7 @@ void phpdbg_eol_convert(char **str, int *len)
}

/* We gonna have a smaller or equally long string, estimation is almost neglecting */
out = (char *)emalloc(out_len);
out = (char *)emalloc(in_len);

last = cur = in[0];
i = cursor = 0;
Expand Down

0 comments on commit 09b2e20

Please sign in to comment.