From: Ivan Maidanski Date: Fri, 20 Jul 2012 08:59:46 +0000 (+0400) Subject: Use memcpy (BCOPY) instead of strcpy (to suppress GCC warning) X-Git-Tag: gc7_4_0~254 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=943c0eb7b97d525da47de7c79c914a432f2c56a2;p=gc Use memcpy (BCOPY) instead of strcpy (to suppress GCC warning) * cord/cordbscs.c (CORD_from_fn, CORD_substr_checked): Use memcpy instead of strcpy (to suppress GCC/ld warning "strcpy() is almost always misused"). * dbg_mlc.c (GC_debug_strdup): Replace strcpy and memcpy with cross-platform BCOPY (with reversed order of "src" and "dest" arguments). * mallocx.c (GC_strdup): Likewise. * misc.c (GC_envfile_init, GC_CreateLogFile): Likewise. * os_dep.c (GC_print_callers): Likewise. --- diff --git a/cord/cordbscs.c b/cord/cordbscs.c index d240fa36..8bc483f7 100644 --- a/cord/cordbscs.c +++ b/cord/cordbscs.c @@ -290,10 +290,10 @@ CORD CORD_from_fn(CORD_fn fn, void * client_data, size_t len) if (c == '\0') goto gen_case; buf[i] = c; } - buf[i] = '\0'; + result = GC_MALLOC_ATOMIC(len+1); if (result == 0) OUT_OF_MEMORY; - strcpy(result, buf); + memcpy(result, buf, len); result[len] = '\0'; return((CORD) result); } @@ -440,10 +440,10 @@ CORD CORD_substr_checked(CORD x, size_t i, size_t n) } *p++ = c; } - *p = '\0'; result = GC_MALLOC_ATOMIC(n+1); if (result == 0) OUT_OF_MEMORY; - strcpy(result, buf); + memcpy(result, buf, n); + result[n] = '\0'; return(result); } } diff --git a/dbg_mlc.c b/dbg_mlc.c index c2e2eaa3..5229677d 100644 --- a/dbg_mlc.c +++ b/dbg_mlc.c @@ -662,12 +662,7 @@ GC_API char * GC_CALL GC_debug_strdup(const char *str, GC_EXTRA_PARAMS) # endif return NULL; } -# ifndef MSWINCE - strcpy(copy, str); -# else - /* strcpy() is deprecated in WinCE */ - memcpy(copy, str, lb); -# endif + BCOPY(str, copy, lb); return copy; } diff --git a/mallocx.c b/mallocx.c index da5a0918..6f3b2064 100644 --- a/mallocx.c +++ b/mallocx.c @@ -568,12 +568,7 @@ GC_API char * GC_CALL GC_strdup(const char *s) # endif return NULL; } -# ifndef MSWINCE - strcpy(copy, s); -# else - /* strcpy() is deprecated in WinCE */ - memcpy(copy, s, lb); -# endif + BCOPY(s, copy, lb); return copy; } diff --git a/misc.c b/misc.c index 5ef96c4f..c4237796 100644 --- a/misc.c +++ b/misc.c @@ -566,7 +566,7 @@ GC_API void GC_CALL GC_get_heap_usage_safe(GC_word *pheap_size, if (len > 4 && path[len - 4] == (TCHAR)'.') { len -= 4; /* strip executable file extension */ } - memcpy(&path[len], TEXT(".gc.env"), sizeof(TEXT(".gc.env"))); + BCOPY(TEXT(".gc.env"), &path[len], sizeof(TEXT(".gc.env"))); hFile = CreateFile(path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL /* lpSecurityAttributes */, OPEN_EXISTING, @@ -1218,9 +1218,8 @@ GC_API void GC_CALL GC_enable_incremental(void) if (len > 4 && pathBuf[len - 4] == (TCHAR)'.') { len -= 4; /* strip executable file extension */ } - /* strcat/wcscat() are deprecated on WinCE, so use memcpy() */ - memcpy(&pathBuf[len], TEXT("." GC_LOG_STD_NAME), - sizeof(TEXT("." GC_LOG_STD_NAME))); + BCOPY(TEXT("." GC_LOG_STD_NAME), &pathBuf[len], + sizeof(TEXT("." GC_LOG_STD_NAME))); # endif } diff --git a/os_dep.c b/os_dep.c index d7d05b9d..eb9a3f66 100644 --- a/os_dep.c +++ b/os_dep.c @@ -4717,11 +4717,12 @@ GC_INNER void GC_print_callers(struct callinfo info[NFRAMES]) (unsigned long)info[i].ci_pc); old_preload = GETENV("LD_PRELOAD"); if (0 != old_preload) { - if (strlen (old_preload) >= PRELOAD_SZ) { + size_t old_len = strlen(old_preload); + if (old_len >= PRELOAD_SZ) { will_fail = TRUE; goto out; } - strcpy (preload_buf, old_preload); + BCOPY(old_preload, preload_buf, old_len + 1); unsetenv ("LD_PRELOAD"); } pipe = popen(cmd_buf, "r"); @@ -4730,8 +4731,8 @@ GC_INNER void GC_print_callers(struct callinfo info[NFRAMES]) WARN("Failed to reset LD_PRELOAD\n", 0); } if (pipe == NULL - || (result_len = fread(result_buf, 1, RESULT_SZ - 1, pipe)) - == 0) { + || (result_len = fread(result_buf, 1, + RESULT_SZ - 1, pipe)) == 0) { if (pipe != NULL) pclose(pipe); will_fail = TRUE; goto out;