From 311d11269eebf7a869c585e44ae703eb21707ff5 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Mon, 8 Dec 2014 21:19:18 -0800 Subject: [PATCH] maint: enable sc_prohibit_strncpy check * cfg.mk (exclude_file_name_regexp--sc_prohibit_strncpy): Remove its exemption. * sed/compile.c (compile_program): Remove two misuses of strncpy; use memcpy instead. * sed/execute.c (do_list): Likewise, for one instance. --- cfg.mk | 1 - sed/compile.c | 4 ++-- sed/execute.c | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/cfg.mk b/cfg.mk index e0316c6..8c46421 100644 --- a/cfg.mk +++ b/cfg.mk @@ -31,7 +31,6 @@ local-checks-to-skip = \ sc_prohibit_atoi_atof \ sc_prohibit_magic_number_exit \ sc_prohibit_strcmp \ - sc_prohibit_strncpy \ sc_texinfo_acronym \ sc_unmarked_diagnostics \ sc_useless_cpp_parens diff --git a/sed/compile.c b/sed/compile.c index 3b9264b..cd86dc4 100644 --- a/sed/compile.c +++ b/sed/compile.c @@ -1272,7 +1272,7 @@ compile_program(struct vector *vector) /* Set the i-th source character. */ trans_pairs[2 * i] = MALLOC(src_lens[i] + 1, char); - strncpy(trans_pairs[2 * i], src_buf, src_lens[i]); + memcpy(trans_pairs[2 * i], src_buf, src_lens[i]); trans_pairs[2 * i][src_lens[i]] = '\0'; src_buf += src_lens[i]; /* Forward to next character. */ @@ -1286,7 +1286,7 @@ compile_program(struct vector *vector) /* Set the i-th destination character. */ trans_pairs[2 * i + 1] = MALLOC(mbclen + 1, char); - strncpy(trans_pairs[2 * i + 1], dest_buf + idx, mbclen); + memcpy(trans_pairs[2 * i + 1], dest_buf + idx, mbclen); trans_pairs[2 * i + 1][mbclen] = '\0'; idx += mbclen; /* Forward to next character. */ } diff --git a/sed/execute.c b/sed/execute.c index c839451..8ef4246 100644 --- a/sed/execute.c +++ b/sed/execute.c @@ -1523,8 +1523,8 @@ execute_program(struct vector *vec, struct input *input) line.length += move_offset; idx += move_offset; } - strncpy(line.active + prev_idx, trans[2*i+1], - trans_len); + memcpy(line.active + prev_idx, trans[2*i+1], + trans_len); break; } }