]> granicus.if.org Git - gc/commitdiff
Use memcpy (BCOPY) instead of strcpy (to suppress GCC warning)
authorIvan Maidanski <ivmai@mail.ru>
Fri, 20 Jul 2012 08:59:46 +0000 (12:59 +0400)
committerIvan Maidanski <ivmai@mail.ru>
Fri, 20 Jul 2012 08:59:46 +0000 (12:59 +0400)
* 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.

cord/cordbscs.c
dbg_mlc.c
mallocx.c
misc.c
os_dep.c

index d240fa36288f74fae34cd48e642c3da33a475e62..8bc483f7489ea1cea52732a0b482d340cdc1e87d 100644 (file)
@@ -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);
         }
     }
index c2e2eaa3d57712c96cec6403a0a45c05d29000da..5229677d28f31a4738949b6295cb4a745ff9efcf 100644 (file)
--- 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;
 }
 
index da5a0918f58e7fbf10ba434ee21aa4e0e83aa246..6f3b206463da694dabff7c4ac3bac86082786622 100644 (file)
--- 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 5ef96c4fb6d34d4fc54ec0d8a60b7f8c67f554d4..c42377962ab649c7b2c783755b5aaa84b5593b46 100644 (file)
--- 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
     }
 
index d7d05b9dbdd16bc2aff5af9551a9d8f4e4d77212..eb9a3f66e4f4d18240d32139452e75f5f563e705 100644 (file)
--- 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;