Using memset before strncpy just to ensure a trailing null
character is an unnecessary double writing of a string

Signed-off-by: Rickard Strandqvist <[email protected]>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to