Module Name: src
Committed By: christos
Date: Thu May 27 13:40:38 UTC 2021
Modified Files:
src/sys/net: dl_print.c
Log Message:
Simplify; no need to special case the small buffer zero src_len.
lla_snprintf1 never returns -1.
To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/net/dl_print.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/net/dl_print.c
diff -u src/sys/net/dl_print.c:1.7 src/sys/net/dl_print.c:1.8
--- src/sys/net/dl_print.c:1.7 Thu May 27 09:36:33 2021
+++ src/sys/net/dl_print.c Thu May 27 09:40:38 2021
@@ -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 @@ lla_snprintf1(char *dst, size_t dst_len,
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 @@ lla_snprintf1(char *dst, size_t dst_len,
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;
}