diff options
-rw-r--r-- | sapi/phpdbg/phpdbg_eol.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/sapi/phpdbg/phpdbg_eol.c b/sapi/phpdbg/phpdbg_eol.c index 50e0056fa8..dc4e07c76c 100644 --- a/sapi/phpdbg/phpdbg_eol.c +++ b/sapi/phpdbg/phpdbg_eol.c @@ -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; @@ -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; |