diff options
author | Anatol Belski <ab@php.net> | 2014-09-19 12:39:17 +0200 |
---|---|---|
committer | Anatol Belski <ab@php.net> | 2014-09-19 12:39:17 +0200 |
commit | 6bbebc60ea0de6ce09ea45094b3bed1823d96cec (patch) | |
tree | 3054f7f6a27a707d63016dd23b0e790ccc2fed3a /Zend | |
parent | d8de53d498cf75936c9cd6781456c39b01f5af60 (diff) | |
download | php-git-6bbebc60ea0de6ce09ea45094b3bed1823d96cec.tar.gz |
avoid multiple strlen calls for the same buffer
Diffstat (limited to 'Zend')
-rw-r--r-- | Zend/zend_virtual_cwd.c | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/Zend/zend_virtual_cwd.c b/Zend/zend_virtual_cwd.c index 665829d685..acc83ec38e 100644 --- a/Zend/zend_virtual_cwd.c +++ b/Zend/zend_virtual_cwd.c @@ -1442,16 +1442,20 @@ CWD_API char *virtual_realpath(const char *path, char *real_path TSRMLS_DC) /* { if (VCWD_GETCWD(cwd, MAXPATHLEN)) { path = cwd; } - } else if (!IS_ABSOLUTE_PATH(path, strlen(path))) { - CWD_STATE_COPY(&new_state, &CWDG(cwd)); } else { - new_state.cwd = (char*)emalloc(1); - if (new_state.cwd == NULL) { - retval = NULL; - goto end; + size_t path_len = strlen(path); + + if (!IS_ABSOLUTE_PATH(path, path_len)) { + CWD_STATE_COPY(&new_state, &CWDG(cwd)); + } else { + new_state.cwd = (char*)emalloc(1); + if (new_state.cwd == NULL) { + retval = NULL; + goto end; + } + new_state.cwd[0] = '\0'; + new_state.cwd_length = 0; } - new_state.cwd[0] = '\0'; - new_state.cwd_length = 0; } if (virtual_file_ex(&new_state, path, NULL, CWD_REALPATH TSRMLS_CC)==0) { @@ -1967,17 +1971,21 @@ CWD_API char *tsrm_realpath(const char *path, char *real_path TSRMLS_DC) /* {{{ if (VCWD_GETCWD(cwd, MAXPATHLEN)) { path = cwd; } - } else if (!IS_ABSOLUTE_PATH(path, strlen(path)) && - VCWD_GETCWD(cwd, MAXPATHLEN)) { - new_state.cwd = estrdup(cwd); - new_state.cwd_length = strlen(cwd); } else { - new_state.cwd = (char*)emalloc(1); - if (new_state.cwd == NULL) { - return NULL; + size_t path_len = strlen(path); + + if (!IS_ABSOLUTE_PATH(path, strlen(path)) && + VCWD_GETCWD(cwd, MAXPATHLEN)) { + new_state.cwd = estrdup(cwd); + new_state.cwd_length = strlen(cwd); + } else { + new_state.cwd = (char*)emalloc(1); + if (new_state.cwd == NULL) { + return NULL; + } + new_state.cwd[0] = '\0'; + new_state.cwd_length = 0; } - new_state.cwd[0] = '\0'; - new_state.cwd_length = 0; } if (virtual_file_ex(&new_state, path, NULL, CWD_REALPATH TSRMLS_CC)) { |