diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2019-04-11 17:44:20 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-04-11 17:44:20 +0200 |
commit | 09b2e2033319af2ba9b90fdc8dc821055742f706 (patch) | |
tree | 3ec1fbeaade679617dc5299af5b9be4855cd0105 /sapi | |
parent | 7bb22df5cf04a13d3cb78113ec6f416b0088c758 (diff) | |
download | php-git-09b2e2033319af2ba9b90fdc8dc821055742f706.tar.gz |
Work around -Walloc-size-larger-than bug
Diffstat (limited to 'sapi')
-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; |