Re: [PATCH] isdn: act2000: capi.c: Cleaning up unnecessary use of memset in conjunction with strncpy

From: Rickard Strandqvist
Date: Sun Sep 14 2014 - 12:13:51 EST


2014-09-14 18:01 GMT+02:00 Rickard Strandqvist
<rickard_strandqvist@xxxxxxxxxxxxxxxxxx>:
> Using memset before strncpy just to ensure a trailing null
> character is an unnecessary double writing of a string
>
> Signed-off-by: Rickard Strandqvist <rickard_strandqvist@xxxxxxxxxxxxxxxxxx>
> ---
> drivers/isdn/act2000/capi.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/isdn/act2000/capi.c b/drivers/isdn/act2000/capi.c
> index 3f66ca2..1267739 100644
> --- a/drivers/isdn/act2000/capi.c
> +++ b/drivers/isdn/act2000/capi.c
> @@ -907,10 +907,10 @@ actcapi_dispatch(struct work_struct *work)
> case 0xff02:
> /* MANUFACTURER_IND */
> if (msg->msg.manuf_msg == 3) {
> - memset(tmp, 0, sizeof(tmp));
> strncpy(tmp,
> &msg->msg.manufacturer_ind_err.errstring,
> - msg->hdr.len - 16);
> + sizeof(tmp));
> + tmp[sizeof(tmp) - 1] = '\0';
> if (msg->msg.manufacturer_ind_err.errcode)
> printk(KERN_WARNING "act2000: %s\n", tmp);
> else {
> @@ -1136,9 +1136,9 @@ actcapi_debug_msg(struct sk_buff *skb, int direction)
> msg->msg.manufacturer_ind_err.controller);
> printk(KERN_DEBUG " Code = 0x%08x\n",
> msg->msg.manufacturer_ind_err.errcode);
> - memset(tmp, 0, sizeof(tmp));
> strncpy(tmp, &msg->msg.manufacturer_ind_err.errstring,
> - msg->hdr.len - 16);
> + sizeof(tmp));
> + tmp[sizeof(tmp) - 1] = '\0';
> printk(KERN_DEBUG " Emsg = '%s'\n", tmp);
> break;
> }
> --
> 1.7.10.4
>

Hi

I'm sorry, this will not give the same effect :-(
Please, ignore this patch!

Kind regards
Rickard Strandqvist
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/