From: Anatol Belski Date: Fri, 19 Sep 2014 10:39:17 +0000 (+0200) Subject: avoid multiple strlen calls for the same buffer X-Git-Tag: POST_NATIVE_TLS_MERGE^2~191 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6bbebc60ea0de6ce09ea45094b3bed1823d96cec;p=php avoid multiple strlen calls for the same buffer --- 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)) {