From: Gerald Pfeifer Subject: cmd: Avoid duplicate invocation of strlenW and make code more more resilient in WCMD_copy. (RESEND) Message-Id: Date: Wed, 2 Apr 2014 22:09:10 -0700 (PDT) Are there any problems with this patch? Gerald ---------- Forwarded message ---------- From: Gerald Pfeifer To: wine-patches@winehq.org Date: Sun, 8 Sep 2013 00:43:45 +0200 (CEST) Subject: cmd: Avoid duplicate invocation of strlenW and make code more more resilient in WCMD_copy. GCC warns about destname[strlenW() - 1] since it cannot see that the string is always non-zero. In any case, we may want to avoid duplicate invocations of strlenW. Gerald --- programs/cmd/builtins.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c index 64e12a0..ed96912 100644 --- a/programs/cmd/builtins.c +++ b/programs/cmd/builtins.c @@ -789,6 +789,7 @@ void WCMD_copy(WCHAR * args) { } else { WCHAR *filenamepart; DWORD attributes; + size_t len; WINE_TRACE("Destination supplied, processing to see if file or directory\n"); @@ -798,12 +799,14 @@ void WCMD_copy(WCHAR * args) { /* If parameter is a directory, ensure it ends in \ */ attributes = GetFileAttributesW(destname); - if ((destname[strlenW(destname) - 1] == '\\') || + len = strlenW(destname); + if ((len && destname[len - 1] == '\\') || ((attributes != INVALID_FILE_ATTRIBUTES) && (attributes & FILE_ATTRIBUTE_DIRECTORY))) { destisdirectory = TRUE; - if (!(destname[strlenW(destname) - 1] == '\\')) strcatW(destname, slashW); + if (!len || destname[len - 1] != '\\') + strcatW(destname, slashW); WINE_TRACE("Directory, so full name is now '%s'\n", wine_dbgstr_w(destname)); } } -- 1.8.3.4