[m-rev.] for review: Avoid gcc stringop-truncation error.

Peter Wang novalazy at gmail.com
Fri Jan 17 16:39:26 AEDT 2020


Avoid these errors, seen when compiling with a gcc 10 snapshot:
    error: ‘strncpy’ output truncated before terminating nul copying 3 bytes
    from a string of the same length [-Werror=stringop-truncation]

runtime/mercury_trace_term.c:
    Replace use of strncpy with memcpy in a private function.
---
 runtime/mercury_trace_term.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/runtime/mercury_trace_term.c b/runtime/mercury_trace_term.c
index 5e9b3b92e..281193c7c 100644
--- a/runtime/mercury_trace_term.c
+++ b/runtime/mercury_trace_term.c
@@ -496,7 +496,7 @@ MR_copy_str_fragment(const char *original, int string_length)
     char    *copy;
 
     copy = MR_malloc(string_length + 1);
-    strncpy(copy, original, string_length);
+    memcpy(copy, original, string_length);
     copy[string_length] = '\0';
     return copy;
 }
-- 
2.25.0



More information about the reviews mailing list