com php-src: Work around -Walloc-size-larger-than bug: sapi/phpdbg/phpdbg_eol.c

From: Date: Thu, 11 Apr 2019 15:44:20 +0000
Subject: com php-src: Work around -Walloc-size-larger-than bug: sapi/phpdbg/phpdbg_eol.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-105670@lists.php.net to get a copy of this message
Commit: 09b2e2033319af2ba9b90fdc8dc821055742f706 Author: Nikita Popov <nikita.ppv@gmail.com> Thu, 11 Apr 2019 17:44:20 +0200 Parents: 7bb22df5cf04a13d3cb78113ec6f416b0088c758 Branches: PHP-7.4 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=09b2e2033319af2ba9b90fdc8dc821055742f706 Log: Work around -Walloc-size-larger-than bug Changed paths: M sapi/phpdbg/phpdbg_eol.c Diff: diff --git a/sapi/phpdbg/phpdbg_eol.c b/sapi/phpdbg/phpdbg_eol.c index 50e0056..dc4e07c 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;

« previous php.cvs (#105670) next »