[m-rev.] for review: Avoid gcc stringop-truncation error.
Julien Fischer
jfischer at opturion.com
Fri Jan 17 16:53:44 AEDT 2020
On Fri, 17 Jan 2020, Peter Wang wrote:
> 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;
> }
s/memcpy/MR_memcpy/
Looks fine otherwise.
Julien.
More information about the reviews
mailing list