Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/net Simplify; no need to special case the small buffer z...



details:   https://anonhg.NetBSD.org/src/rev/3fa915f4fb64
branches:  trunk
changeset: 1021354:3fa915f4fb64
user:      christos <christos%NetBSD.org@localhost>
date:      Thu May 27 13:40:38 2021 +0000

description:
Simplify; no need to special case the small buffer zero src_len.
lla_snprintf1 never returns -1.

diffstat:

 sys/net/dl_print.c |  20 +++++++-------------
 1 files changed, 7 insertions(+), 13 deletions(-)

diffs (56 lines):

diff -r 3959721e65d3 -r 3fa915f4fb64 sys/net/dl_print.c
--- a/sys/net/dl_print.c        Thu May 27 13:36:33 2021 +0000
+++ b/sys/net/dl_print.c        Thu May 27 13:40:38 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dl_print.c,v 1.7 2021/05/27 13:36:33 christos Exp $    */
+/*     $NetBSD: dl_print.c,v 1.8 2021/05/27 13:40:38 christos Exp $    */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -29,10 +29,10 @@
 #include <sys/types.h>
 
 #ifdef _KERNEL
-__KERNEL_RCSID(0, "$NetBSD: dl_print.c,v 1.7 2021/05/27 13:36:33 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dl_print.c,v 1.8 2021/05/27 13:40:38 christos Exp $");
 #include <sys/systm.h>
 #else
-__RCSID("$NetBSD: dl_print.c,v 1.7 2021/05/27 13:36:33 christos Exp $");
+__RCSID("$NetBSD: dl_print.c,v 1.8 2021/05/27 13:40:38 christos Exp $");
 #include <stdio.h>
 static const char hexdigits[] = "0123456789abcdef";
 #endif
@@ -44,12 +44,6 @@
        char *dp;
        const uint8_t *sp, *ep;
 
-       if (src_len == 0 || dst_len < 3) {
-               if (dst_len != 0)
-                       dst[0] = '\0';
-               return src_len ? (int)(src_len * 3) - 1 : 0;
-       }
-
        dp = dst;
        sp = (const uint8_t *)src;
        ep = sp + src_len;
@@ -64,16 +58,16 @@
                        break;
                *dp++ = ':';
        }
-       *--dp = '\0';
+       if (dp != dst)
+               *--dp = '\0';
 
-       return (int)(src_len * 3) - 1;
+       return src_len ? (int)(src_len * 3) - 1 : 0;
 }
 
 char *
 lla_snprintf(char *dst, size_t dst_len, const void *src, size_t src_len)
 {
-       if (lla_snprintf1(dst, dst_len, src, src_len) == -1)
-               return NULL;
+       (void)lla_snprintf1(dst, dst_len, src, src_len);
        return dst;
 }
 



Home | Main Index | Thread Index | Old Index