com php-src: get rid of two strlen calls: TSRM/tsrm_win32 .c TSRM/tsrm_win32.h Zend/zend_virtual_cwd. c

[email protected] (Anatol Belski)
Newsgroups php.cvs
Message-ID <[email protected]>
Commit:    24ae881080f8cfbb56e0981973d4474a831a3398
Author:    Anatol Belski <[email protected]>         Thu, 27 Apr 2017 15:39:32 +0200
Parents:   84b397bf44d656cdedbf9a10aae33f4b51736ccf
Branches:  master

Link:       http://git.php.net/?p=php-src.git;a=commitdiff;h=24ae881080f8cfbb56e0981973d4474a831a3398

Log:
get rid of two strlen calls

Changed paths:
  M  TSRM/tsrm_win32.c
  M  TSRM/tsrm_win32.h
  M  Zend/zend_virtual_cwd.c


Diff:
diff --git a/TSRM/tsrm_win32.c b/TSRM/tsrm_win32.c
index 84d1539..4bd1fcb 100644
--- a/TSRM/tsrm_win32.c
+++ b/TSRM/tsrm_win32.c
@@ -107,33 +107,36 @@ TSRM_API void tsrm_win32_shutdown(void)
 #endif
 }
 
-char * tsrm_win32_get_path_sid_key(const char *pathname)
+char * tsrm_win32_get_path_sid_key(const char *pathname, size_t pathname_len, size_t *key_len)
 {
 	PSID pSid = TWG(impersonation_token_sid);
 	TCHAR *ptcSid = NULL;
 	char *bucket_key = NULL;
-	size_t ptc_sid_len, pathname_len;
-
-	pathname_len = strlen(pathname);
+	size_t ptc_sid_len;
 
 	if (!pSid) {
 		bucket_key = (char *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, pathname_len + 1);
 		if (!bucket_key) {
+			*key_len = 0;
 			return NULL;
 		}
 		memcpy(bucket_key, pathname, pathname_len);
+		*key_len = pathname_len;
 		return bucket_key;
 	}
 
 	if (!ConvertSidToStringSid(pSid, &ptcSid)) {
+		*key_len = 0;
 		return NULL;
 	}
 
 
 	ptc_sid_len = strlen(ptcSid);
-	bucket_key = (char *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, pathname_len + ptc_sid_len + 1);
+	*key_len = pathname_len + ptc_sid_len;
+	bucket_key = (char *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *key_len + 1);
 	if (!bucket_key) {
 		LocalFree(ptcSid);
+		*key_len = 0;
 		return NULL;
 	}
 
diff --git a/TSRM/tsrm_win32.h b/TSRM/tsrm_win32.h
index 8220229..dc74f79 100644
--- a/TSRM/tsrm_win32.h
+++ b/TSRM/tsrm_win32.h
@@ -95,7 +95,7 @@ TSRMLS_CACHE_EXTERN()
 #define	SHM_RND		FILE_MAP_WRITE
 #define	SHM_REMAP	FILE_MAP_COPY
 
-char * tsrm_win32_get_path_sid_key(const char *pathname );
+char * tsrm_win32_get_path_sid_key(const char *pathname, size_t pathname_len, size_t *key_len);
 
 TSRM_API void tsrm_win32_startup(void);
 TSRM_API void tsrm_win32_shutdown(void);
diff --git a/Zend/zend_virtual_cwd.c b/Zend/zend_virtual_cwd.c
index fd19892..2f9c46d 100644
--- a/Zend/zend_virtual_cwd.c
+++ b/Zend/zend_virtual_cwd.c
@@ -525,7 +525,8 @@ CWD_API char *virtual_getcwd(char *buf, size_t size) /* {{{ */
 static inline zend_ulong realpath_cache_key(const char *path, size_t path_len) /* {{{ */
 {
 	register zend_ulong h;
-	char *bucket_key_start = tsrm_win32_get_path_sid_key(path);
+	size_t bucket_key_len;
+	char *bucket_key_start = tsrm_win32_get_path_sid_key(path, path_len, &bucket_key_len);
 	char *bucket_key = (char *)bucket_key_start;
 	const char *e;
 
@@ -533,7 +534,7 @@ static inline zend_ulong realpath_cache_key(const char *path, size_t path_len) /
 		return 0;
 	}
 
-	e = bucket_key + strlen(bucket_key);
+	e = bucket_key + bucket_key_len;
 	for (h = Z_UL(2166136261); bucket_key < e;) {
 		h *= Z_UL(16777619);
 		h ^= *bucket_key++;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.