libbsd: Branch 'master' - 12 commits

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Jun 18 09:55:22 UTC 2018


 configure.ac             |    4 +--
 include/bsd/err.h        |   12 ++++-----
 include/bsd/getopt.h     |    6 ++++
 include/bsd/sys/cdefs.h  |   37 ++++++++++++++++------------
 include/bsd/sys/endian.h |    6 ++++
 include/bsd/sys/time.h   |    6 ++++
 include/bsd/unistd.h     |   13 +++++-----
 src/arc4random.c         |    6 ++--
 src/explicit_bzero.c     |    2 -
 src/flopen.c             |    1 
 src/hash/helper.c        |    3 ++
 src/inet_net_pton.c      |    5 +++
 src/local-link.h         |    2 -
 src/setproctitle.c       |    9 ++++--
 src/setproctitle_ctor.c  |    2 -
 src/unvis.c              |    3 +-
 src/vis.c                |   61 ++++++++++++++++++++++++++++-------------------
 test/overlay.c           |    2 +
 18 files changed, 117 insertions(+), 63 deletions(-)

New commits:
commit 7cfa2d4530325444fa71c2bdb14e11ba9d4de0b6
Author: Aaron Dierking <aarond at fb.com>
Date:   Thu Jun 14 11:38:31 2018 -0700

    Correct Clang feature detection
    
    Clang's __GNUC__ and __GNUC_MINOR__ definitions are not reliable and may
    not be defined at all when targeting the MSVC ABI. Use feature-checking
    macros when possible or check for __clang__.
    
    [guillem at hadrons.org: Update for __ protected keyword change. ]
    
    Signed-off-by: Guillem Jover <guillem at hadrons.org>

diff --git a/include/bsd/sys/cdefs.h b/include/bsd/sys/cdefs.h
index c574fc2..999bda2 100644
--- a/include/bsd/sys/cdefs.h
+++ b/include/bsd/sys/cdefs.h
@@ -30,6 +30,13 @@
 #ifndef __has_include_next
 #define __has_include_next(x) 1
 #endif
+#ifndef __has_attribute
+#define __has_attribute(x) 0
+#endif
+/* Clang expands this to 1 if an identifier is *not* reserved. */
+#ifndef __is_identifier
+#define __is_identifier(x) 1
+#endif
 
 #ifdef LIBBSD_OVERLAY
 /*
@@ -85,7 +92,7 @@
 #define LIBBSD_GCC_VERSION 0
 #endif
 
-#if LIBBSD_GCC_VERSION >= 0x0405
+#if LIBBSD_GCC_VERSION >= 0x0405 || __has_attribute(__deprecated__)
 #define LIBBSD_DEPRECATED(x) __attribute__((__deprecated__(x)))
 #elif LIBBSD_GCC_VERSION >= 0x0301
 #define LIBBSD_DEPRECATED(x) __attribute__((__deprecated__))
@@ -93,14 +100,14 @@
 #define LIBBSD_DEPRECATED(x)
 #endif
 
-#if LIBBSD_GCC_VERSION >= 0x0200
+#if LIBBSD_GCC_VERSION >= 0x0200 || defined(__clang__)
 #define LIBBSD_REDIRECT(name, proto, alias) name proto __asm__(LIBBSD_ASMNAME(#alias))
 #endif
 #define LIBBSD_ASMNAME(cname) LIBBSD_ASMNAME_PREFIX(__USER_LABEL_PREFIX__, cname)
 #define LIBBSD_ASMNAME_PREFIX(prefix, cname) LIBBSD_STRING(prefix) cname
 
 #ifndef __dead2
-# if LIBBSD_GCC_VERSION >= 0x0207
+# if LIBBSD_GCC_VERSION >= 0x0207 || __has_attribute(__noreturn__)
 #  define __dead2 __attribute__((__noreturn__))
 # else
 #  define __dead2
@@ -108,7 +115,7 @@
 #endif
 
 #ifndef __pure2
-# if LIBBSD_GCC_VERSION >= 0x0207
+# if LIBBSD_GCC_VERSION >= 0x0207 || __has_attribute(__const__)
 #  define __pure2 __attribute__((__const__))
 # else
 #  define __pure2
@@ -116,7 +123,7 @@
 #endif
 
 #ifndef __packed
-# if LIBBSD_GCC_VERSION >= 0x0207
+# if LIBBSD_GCC_VERSION >= 0x0207 || __has_attribute(__packed__)
 #  define __packed __attribute__((__packed__))
 # else
 #  define __packed
@@ -124,7 +131,7 @@
 #endif
 
 #ifndef __aligned
-# if LIBBSD_GCC_VERSION >= 0x0207
+# if LIBBSD_GCC_VERSION >= 0x0207 || __has_attribute(__aligned__)
 #  define __aligned(x) __attribute__((__aligned__(x)))
 # else
 #  define __aligned(x)
@@ -145,7 +152,7 @@
 #endif
 
 #ifndef __printflike
-# if LIBBSD_GCC_VERSION >= 0x0300
+# if LIBBSD_GCC_VERSION >= 0x0300 || __has_attribute(__format__)
 #  define __printflike(x, y) __attribute((__format__(__printf__, (x), (y))))
 # else
 #  define __printflike(x, y)
@@ -153,7 +160,7 @@
 #endif
 
 #ifndef __nonnull
-# if LIBBSD_GCC_VERSION >= 0x0302
+# if LIBBSD_GCC_VERSION >= 0x0302 || __has_attribute(__nonnull__)
 #  define __nonnull(x) __attribute__((__nonnull__(x)))
 # else
 #  define __nonnull(x)
@@ -175,7 +182,7 @@
  * require it.
  */
 #ifndef __offsetof
-# if LIBBSD_GCC_VERSION >= 0x0401
+# if LIBBSD_GCC_VERSION >= 0x0401 || !__is_identifier(__builtin_offsetof)
 #  define __offsetof(type, field)	__builtin_offsetof(type, field)
 # else
 #  ifndef __cplusplus
@@ -200,7 +207,7 @@
  * compatible with member m.
  */
 #ifndef __containerof
-# if LIBBSD_GCC_VERSION >= 0x0301
+# if LIBBSD_GCC_VERSION >= 0x0301 || !__is_identifier(__typeof__)
 #  define __containerof(x, s, m) ({ \
 	const volatile __typeof__(((s *)0)->m) *__x = (x); \
 	__DEQUALIFY(s *, (const volatile char *)__x - __offsetof(s, m)); \
diff --git a/src/arc4random.c b/src/arc4random.c
index c6f89c3..1a7b72f 100644
--- a/src/arc4random.c
+++ b/src/arc4random.c
@@ -39,11 +39,11 @@
 
 #define minimum(a, b) ((a) < (b) ? (a) : (b))
 
-#if defined(__GNUC__) || defined(_MSC_VER)
+#if defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER)
 #define inline __inline
-#else				/* __GNUC__ || _MSC_VER */
+#else				/* __GNUC__ || __clang__ || _MSC_VER */
 #define inline
-#endif				/* !__GNUC__ && !_MSC_VER */
+#endif				/* !__GNUC__ && !__clang__ && !_MSC_VER */
 
 #define KEYSZ	32
 #define IVSZ	8
commit 574c7a1365b729343494181f36376d378b54fdea
Author: Guillem Jover <guillem at hadrons.org>
Date:   Mon Jun 18 00:36:44 2018 +0200

    Protect C language extensions with two leading and trailing underscores
    
    This should make their usage safer against user macros.

diff --git a/configure.ac b/configure.ac
index 7769182..6b2bb6c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -87,7 +87,7 @@ AC_CACHE_CHECK(
 [[
 static int rc = 1;
 static void init(int argc) { if (argc == 1) rc = 0; }
-void (*init_func)(int argc) __attribute__((section(".init_array"))) = init;
+void (*init_func)(int argc) __attribute__((__section__(".init_array"))) = init;
 int main() { return rc; }
 ]]
 		)],
diff --git a/include/bsd/sys/cdefs.h b/include/bsd/sys/cdefs.h
index b5c8dad..c574fc2 100644
--- a/include/bsd/sys/cdefs.h
+++ b/include/bsd/sys/cdefs.h
@@ -86,9 +86,9 @@
 #endif
 
 #if LIBBSD_GCC_VERSION >= 0x0405
-#define LIBBSD_DEPRECATED(x) __attribute__((deprecated(x)))
+#define LIBBSD_DEPRECATED(x) __attribute__((__deprecated__(x)))
 #elif LIBBSD_GCC_VERSION >= 0x0301
-#define LIBBSD_DEPRECATED(x) __attribute__((deprecated))
+#define LIBBSD_DEPRECATED(x) __attribute__((__deprecated__))
 #else
 #define LIBBSD_DEPRECATED(x)
 #endif
@@ -137,7 +137,7 @@
 #if 0
 #ifndef __unused
 # if LIBBSD_GCC_VERSION >= 0x0300
-#  define __unused __attribute__((unused))
+#  define __unused __attribute__((__unused__))
 # else
 #  define __unused
 # endif
@@ -146,7 +146,7 @@
 
 #ifndef __printflike
 # if LIBBSD_GCC_VERSION >= 0x0300
-#  define __printflike(x, y) __attribute((format(printf, (x), (y))))
+#  define __printflike(x, y) __attribute((__format__(__printf__, (x), (y))))
 # else
 #  define __printflike(x, y)
 # endif
@@ -202,7 +202,7 @@
 #ifndef __containerof
 # if LIBBSD_GCC_VERSION >= 0x0301
 #  define __containerof(x, s, m) ({ \
-	const volatile __typeof(((s *)0)->m) *__x = (x); \
+	const volatile __typeof__(((s *)0)->m) *__x = (x); \
 	__DEQUALIFY(s *, (const volatile char *)__x - __offsetof(s, m)); \
 })
 # else
diff --git a/src/explicit_bzero.c b/src/explicit_bzero.c
index 3e33ca8..52a7517 100644
--- a/src/explicit_bzero.c
+++ b/src/explicit_bzero.c
@@ -6,7 +6,7 @@
 
 #include <string.h>
 
-__attribute__((weak)) void
+__attribute__((__weak__)) void
 __explicit_bzero_hook(void *buf, size_t len)
 {
 }
diff --git a/src/local-link.h b/src/local-link.h
index d518dcf..5f3c0fd 100644
--- a/src/local-link.h
+++ b/src/local-link.h
@@ -29,5 +29,5 @@
 
 #define libbsd_link_warning(symbol, msg) \
 	static const char libbsd_emit_link_warning_##symbol[] \
-		__attribute__((used,section(".gnu.warning." #symbol))) = msg;
+		__attribute__((__used__,__section__(".gnu.warning." #symbol))) = msg;
 #endif
diff --git a/src/setproctitle.c b/src/setproctitle.c
index 038ac7d..6329bf4 100644
--- a/src/setproctitle.c
+++ b/src/setproctitle.c
@@ -287,9 +287,12 @@ __asm__(".symver setproctitle_impl,setproctitle@@LIBBSD_0.5");
  * for code linking against that version, and change the default to use the
  * new version, so that new code depends on the implemented version. */
 #ifdef HAVE_TYPEOF
-extern typeof(setproctitle_impl) setproctitle_stub __attribute__((alias("setproctitle_impl")));
+extern __typeof__(setproctitle_impl)
+setproctitle_stub
+	__attribute__((__alias__("setproctitle_impl")));
 #else
-void setproctitle_stub(const char *fmt, ...)
-	__attribute__((alias("setproctitle_impl")));
+void
+setproctitle_stub(const char *fmt, ...)
+	__attribute__((__alias__("setproctitle_impl")));
 #endif
 __asm__(".symver setproctitle_stub,setproctitle at LIBBSD_0.2");
diff --git a/src/setproctitle_ctor.c b/src/setproctitle_ctor.c
index 9360774..2c5b6d0 100644
--- a/src/setproctitle_ctor.c
+++ b/src/setproctitle_ctor.c
@@ -49,4 +49,4 @@
  * move them from .ctors to .init_array.
  */
 void (*libbsd_init_func)(int argc, char *argv[], char *envp[])
-	__attribute__((section(".init_array"))) = setproctitle_init;
+	__attribute__((__section__(".init_array"))) = setproctitle_init;
commit c2d9d8408869af50fd5802542a4f032375e5e7bc
Author: Aaron Dierking <aarond at fb.com>
Date:   Thu Jun 14 11:38:32 2018 -0700

    Guard non-portable forwarded includes
    
    These headers are not available on Windows. <bsd/sys/cdefs.h> ensures
    that __has_include() and __has_include_next() are defined.
    
    Signed-off-by: Guillem Jover <guillem at hadrons.org>

diff --git a/include/bsd/err.h b/include/bsd/err.h
index 12fd051..cf043e4 100644
--- a/include/bsd/err.h
+++ b/include/bsd/err.h
@@ -26,20 +26,20 @@
  */
 
 #ifdef LIBBSD_OVERLAY
+#include <sys/cdefs.h>
+#if __has_include_next(<err.h>)
 #include_next <err.h>
+#endif
 #else
+#include <bsd/sys/cdefs.h>
+#if __has_include(<err.h>)
 #include <err.h>
 #endif
+#endif
 
 #ifndef LIBBSD_ERR_H
 #define LIBBSD_ERR_H
 
-#ifdef LIBBSD_OVERLAY
-#include <sys/cdefs.h>
-#else
-#include <bsd/sys/cdefs.h>
-#endif
-
 #include <stdarg.h>
 
 __BEGIN_DECLS
diff --git a/include/bsd/getopt.h b/include/bsd/getopt.h
index a6505e9..48c3be8 100644
--- a/include/bsd/getopt.h
+++ b/include/bsd/getopt.h
@@ -25,9 +25,15 @@
  */
 
 #ifdef LIBBSD_OVERLAY
+#include <sys/cdefs.h>
+#if __has_include_next(<getopt.h>)
 #include_next <getopt.h>
+#endif
 #include <unistd.h>
 #else
+#include <bsd/sys/cdefs.h>
+#if __has_include(<getopt.h>)
 #include <getopt.h>
+#endif
 #include <bsd/unistd.h>
 #endif
diff --git a/include/bsd/sys/endian.h b/include/bsd/sys/endian.h
index 1af844c..a4a8e9c 100644
--- a/include/bsd/sys/endian.h
+++ b/include/bsd/sys/endian.h
@@ -27,10 +27,16 @@
  */
 
 #ifdef LIBBSD_OVERLAY
+#include <sys/cdefs.h>
+#if __has_include_next(<endian.h>)
 #include_next <endian.h>
+#endif
 #else
+#include <bsd/sys/cdefs.h>
+#if __has_include(<endian.h>)
 #include <endian.h>
 #endif
+#endif
 
 #ifndef LIBBSD_SYS_ENDIAN_H
 #define LIBBSD_SYS_ENDIAN_H
diff --git a/include/bsd/sys/time.h b/include/bsd/sys/time.h
index 0aaf0e2..1eaa76b 100644
--- a/include/bsd/sys/time.h
+++ b/include/bsd/sys/time.h
@@ -33,10 +33,16 @@
  */
 
 #ifdef LIBBSD_OVERLAY
+#include <sys/cdefs.h>
+#if __has_include_next(<sys/time.h>)
 #include_next <sys/time.h>
+#endif
 #else
+#include <bsd/sys/cdefs.h>
+#if __has_include(<sys/time.h>)
 #include <sys/time.h>
 #endif
+#endif
 
 #ifndef LIBBSD_SYS_TIME_H
 #define LIBBSD_SYS_TIME_H
diff --git a/include/bsd/unistd.h b/include/bsd/unistd.h
index c25977d..167241b 100644
--- a/include/bsd/unistd.h
+++ b/include/bsd/unistd.h
@@ -26,19 +26,20 @@
  */
 
 #ifdef LIBBSD_OVERLAY
+#include <sys/cdefs.h>
+#if __has_include_next(<unistd.h>)
 #include_next <unistd.h>
+#endif
 #else
+#include <bsd/sys/cdefs.h>
+#if __has_include(<unistd.h>)
 #include <unistd.h>
 #endif
+#endif
 
 #ifndef LIBBSD_UNISTD_H
 #define LIBBSD_UNISTD_H
 
-#ifdef LIBBSD_OVERLAY
-#include <sys/cdefs.h>
-#else
-#include <bsd/sys/cdefs.h>
-#endif
 #include <sys/stat.h>
 
 #if !defined(S_ISTXT) && defined(S_ISVTX)
commit 2ebe6d5a025dc9762db2b1854d966639e1920e60
Author: Aaron Dierking <aarond at fb.com>
Date:   Thu Jun 14 11:38:32 2018 -0700

    Windows support for inet_net_pton()
    
    Signed-off-by: Guillem Jover <guillem at hadrons.org>

diff --git a/src/inet_net_pton.c b/src/inet_net_pton.c
index 4614248..c3d882b 100644
--- a/src/inet_net_pton.c
+++ b/src/inet_net_pton.c
@@ -19,9 +19,14 @@
 
 #include <sys/cdefs.h>
 #include <sys/types.h>
+#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <WinSock2.h>
+#else
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#endif
 
 #include <assert.h>
 #include <ctype.h>
commit aeea1f408381007aefdd391fab6d9fdb47c69521
Author: Aaron Dierking <aarond at fb.com>
Date:   Thu Jun 14 11:38:32 2018 -0700

    Windows support for HASHFileChunk()
    
    <io.h> provides the necessary file I/O functions.
    
    [guillem at hadrons.org: Move include before <hashinc>. ]
    
    Signed-off-by: Guillem Jover <guillem at hadrons.org>

diff --git a/src/hash/helper.c b/src/hash/helper.c
index d9362d3..352f978 100644
--- a/src/hash/helper.c
+++ b/src/hash/helper.c
@@ -19,6 +19,9 @@
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
+#ifdef _WIN32
+#include <io.h>
+#endif
 
 #include <hashinc>
 
commit 0500a1bd086d2d6fe974e7ded7ea615594f1f7b0
Author: Aaron Dierking <aarond at fb.com>
Date:   Thu Jun 14 11:38:32 2018 -0700

    Don't require <grp.h>
    
    This is only used in the overlay test and Windows does not provide it.
    
    Signed-off-by: Guillem Jover <guillem at hadrons.org>

diff --git a/configure.ac b/configure.ac
index 55fcfe6..7769182 100644
--- a/configure.ac
+++ b/configure.ac
@@ -59,7 +59,7 @@ AS_CASE([$host_os],
 )
 
 # Checks for header files.
-AC_CHECK_HEADERS([sys/ndir.h sys/dir.h ndir.h dirent.h])
+AC_CHECK_HEADERS([sys/ndir.h sys/dir.h ndir.h dirent.h grp.h])
 
 # Checks for typedefs, structures, and compiler characteristics.
 AC_C_INLINE
diff --git a/test/overlay.c b/test/overlay.c
index 7812fcc..a17904f 100644
--- a/test/overlay.c
+++ b/test/overlay.c
@@ -28,7 +28,9 @@
  * other headers through magic macros, to check that the overlay is working
  * properly. */
 #include <errno.h>
+#ifdef HAVE_GRP_H
 #include <grp.h>
+#endif
 #include <stdint.h>
 
 /* Include libbsd overlayed headers that might get partially included. */
commit 3d9c6c08ed254cfe16fc53867b1fe6f12031873c
Author: Aaron Dierking <aarond at fb.com>
Date:   Thu Jun 14 11:38:32 2018 -0700

    Only define S_ISTXT if S_ISVTX is defined
    
    Windows doesn't provide S_ISVTX. Prefer not defining it rather than
    defining it to something invalid.
    
    Signed-off-by: Guillem Jover <guillem at hadrons.org>

diff --git a/include/bsd/unistd.h b/include/bsd/unistd.h
index 1f9c5f8..c25977d 100644
--- a/include/bsd/unistd.h
+++ b/include/bsd/unistd.h
@@ -41,7 +41,7 @@
 #endif
 #include <sys/stat.h>
 
-#ifndef S_ISTXT
+#if !defined(S_ISTXT) && defined(S_ISVTX)
 #define S_ISTXT S_ISVTX
 #endif
 
commit b9dee9f69a6e9f03418bde5638642ddc8df18f74
Author: Aaron Dierking <aarond at fb.com>
Date:   Thu Jun 14 11:38:31 2018 -0700

    Use CHAR_BIT instead of NBBY in strnvis()
    
    <sys/param.h> is not available on Windows.
    
    Signed-off-by: Guillem Jover <guillem at hadrons.org>

diff --git a/src/vis.c b/src/vis.c
index 3e6ade8..260d3c1 100644
--- a/src/vis.c
+++ b/src/vis.c
@@ -57,7 +57,6 @@
 
 #include <sys/cdefs.h>
 #include <sys/types.h>
-#include <sys/param.h>
 
 #include <assert.h>
 #pragma GCC diagnostic push
@@ -308,7 +307,7 @@ do_svis(wchar_t *dst, wint_t c, int flags, wint_t nextc, const wchar_t *extra)
 	/* See comment in istrsenvisx() output loop, below. */
 	wmsk = 0;
 	for (i = sizeof(wmsk) - 1; i >= 0; i--) {
-		shft = i * NBBY;
+		shft = i * CHAR_BIT;
 		bmsk = (uint64_t)0xffLL << shft;
 		wmsk |= bmsk;
 		if ((c & wmsk) || i == 0)
@@ -539,7 +538,7 @@ istrsenvisx(char **mbdstp, size_t *dlen, const char *mbsrc, size_t mblength,
 			clen = 0;
 			wmsk = 0;
 			for (i = sizeof(wmsk) - 1; i >= 0; i--) {
-				shft = i * NBBY;
+				shft = i * CHAR_BIT;
 				bmsk = (uint64_t)0xffLL << shft;
 				wmsk |= bmsk;
 				if ((*dst & wmsk) || i == 0)
commit 81c3c3e4054f88049c4401b1d472188c75bdd5e4
Author: Aaron Dierking <aarond at fb.com>
Date:   Thu Jun 14 11:38:31 2018 -0700

    Replace reintroduced legacy u_* type usage in strnvis() and strnunvis()
    
    This fixes a regression caused by 2d7de18. These types are not available
    on all systems.
    
    Fixes: commit 2d7de186e9cb19a756c0630ee85cb3f2d29b3484
    Signed-off-by: Guillem Jover <guillem at hadrons.org>

diff --git a/src/unvis.c b/src/unvis.c
index 94e3e7a..ae963aa 100644
--- a/src/unvis.c
+++ b/src/unvis.c
@@ -68,7 +68,8 @@ __weak_alias(strnunvisx,_strnunvisx)
 #define	S_NUMBER	14	/* collecting number */
 #define	S_STRING	15	/* collecting string */
 
-#define	isoctal(c)	(((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')
+#define	isoctal(c) \
+	(((unsigned char)(c)) >= '0' && ((unsigned char)(c)) <= '7')
 #define	xtod(c)		(isdigit(c) ? (c - '0') : ((tolower(c) - 'a') + 10))
 #define	XTOD(c)		(isdigit(c) ? (c - '0') : ((c - 'A') + 10))
 
diff --git a/src/vis.c b/src/vis.c
index 674d971..3e6ade8 100644
--- a/src/vis.c
+++ b/src/vis.c
@@ -117,7 +117,8 @@ iscgraph(int c) {
 #define ISGRAPH(flags, c) \
     (((flags) & VIS_NOLOCALE) ? iscgraph(c) : iswgraph(c))
 
-#define iswoctal(c)	(((u_char)(c)) >= L'0' && ((u_char)(c)) <= L'7')
+#define iswoctal(c)	\
+	(((unsigned char)(c)) >= L'0' && ((unsigned char)(c)) <= L'7')
 #define iswwhite(c)	(c == L' ' || c == L'\t' || c == L'\n')
 #define iswsafe(c)	(c == L'\b' || c == BELL || c == L'\r')
 #define xtoa(c)		L"0123456789abcdef"[c]
@@ -253,9 +254,11 @@ do_mbyte(wchar_t *dst, wint_t c, int flags, wint_t nextc, int iswextra)
 	}
 	if (iswextra || ((c & 0177) == L' ') || (flags & VIS_OCTAL)) {
 		*dst++ = L'\\';
-		*dst++ = (u_char)(((u_int32_t)(u_char)c >> 6) & 03) + L'0';
-		*dst++ = (u_char)(((u_int32_t)(u_char)c >> 3) & 07) + L'0';
-		*dst++ =			     (c	      & 07) + L'0';
+		*dst++ =
+			(unsigned char)(((uint32_t)(unsigned char)c >> 6) & 03) + L'0';
+		*dst++ =
+			(unsigned char)(((uint32_t)(unsigned char)c >> 3) & 07) + L'0';
+		*dst++ = (c & 07) + L'0';
 	} else {
 		if ((flags & VIS_NOSLASH) == 0)
 			*dst++ = L'\\';
@@ -349,7 +352,7 @@ makeextralist(int flags, const char *src)
 	if ((flags & VIS_NOLOCALE) || mbstowcs(dst, src, len) == (size_t)-1) {
 		size_t i;
 		for (i = 0; i < len; i++)
-			dst[i] = (wchar_t)(u_char)src[i];
+			dst[i] = (wchar_t)(unsigned char)src[i];
 		d = dst + len;
 	} else
 		d = dst + wcslen(dst);
@@ -452,7 +455,7 @@ istrsenvisx(char **mbdstp, size_t *dlen, const char *mbsrc, size_t mblength,
 			clen = mbtowc(src, mbsrc, MB_LEN_MAX);
 		if (cerr || clen < 0) {
 			/* Conversion error, process as a byte instead. */
-			*src = (wint_t)(u_char)*mbsrc;
+			*src = (wint_t)(unsigned char)*mbsrc;
 			clen = 1;
 			cerr = 1;
 		}
commit 5e0998fa4f0300ec99d0e30c994a500d91cb40c1
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sat Jun 9 00:08:14 2018 +0200

    Remove dead code in vis
    
    The loop only executes while len > 0, and the trinary operator in the
    function argument is checking against len >= 1 which will always be
    true.
    
    Warned-by: coverity

diff --git a/src/vis.c b/src/vis.c
index f17d322..674d971 100644
--- a/src/vis.c
+++ b/src/vis.c
@@ -503,7 +503,7 @@ istrsenvisx(char **mbdstp, size_t *dlen, const char *mbsrc, size_t mblength,
 	 */
 	for (start = dst; len > 0; len--) {
 		c = *src++;
-		dst = (*f)(dst, c, flags, len >= 1 ? *src : L'\0', extra);
+		dst = (*f)(dst, c, flags, *src, extra);
 		if (dst == NULL) {
 			errno = ENOSPC;
 			goto out;
commit 8e2d55047cc9febe38db2b44c4942dd221f182eb
Author: Guillem Jover <guillem at hadrons.org>
Date:   Wed Jun 6 05:41:34 2018 +0200

    Fix vis family of functions to not leak
    
    The code uses an internal helper function to avoid code repetition. But
    to get there, the function takes a pointer to a pointer, so that the few
    functions that require returning an allocated buffer can get hold of it
    this way.
    
    The problem is that the user might pass a NULL pointer and trigger an
    internal allocation even if the functions are not expected to do so.
    
    Add a new internal helper for non-allocations, that will assert that
    condition, and make any other function that requires this behavior call
    this one instead.
    
    Warned-by: coverity

diff --git a/src/vis.c b/src/vis.c
index c2cd2d8..f17d322 100644
--- a/src/vis.c
+++ b/src/vis.c
@@ -580,10 +580,20 @@ out:
 }
 
 static int
-istrsenvisxl(char **mbdstp, size_t *dlen, const char *mbsrc,
+istrsenvisxna(char *mbdst, size_t *dlen, const char *mbsrc, size_t mblength,
     int flags, const char *mbextra, int *cerr_ptr)
 {
-	return istrsenvisx(mbdstp, dlen, mbsrc,
+	assert(mbdst != NULL);
+
+	return istrsenvisx(&mbdst, dlen, mbsrc, mblength,
+	    flags, mbextra, cerr_ptr);
+}
+
+static int
+istrsenvisxl(char *mbdst, size_t *dlen, const char *mbsrc,
+    int flags, const char *mbextra, int *cerr_ptr)
+{
+	return istrsenvisxna(mbdst, dlen, mbsrc,
 	    mbsrc != NULL ? strlen(mbsrc) : 0, flags, mbextra, cerr_ptr);
 }
 
@@ -628,33 +638,33 @@ snvis(char *mbdst, size_t dlen, int c, int flags, int nextc, const char *mbextra
 int
 strsvis(char *mbdst, const char *mbsrc, int flags, const char *mbextra)
 {
-	return istrsenvisxl(&mbdst, NULL, mbsrc, flags, mbextra, NULL);
+	return istrsenvisxl(mbdst, NULL, mbsrc, flags, mbextra, NULL);
 }
 
 int
 strsnvis(char *mbdst, size_t dlen, const char *mbsrc, int flags, const char *mbextra)
 {
-	return istrsenvisxl(&mbdst, &dlen, mbsrc, flags, mbextra, NULL);
+	return istrsenvisxl(mbdst, &dlen, mbsrc, flags, mbextra, NULL);
 }
 
 int
 strsvisx(char *mbdst, const char *mbsrc, size_t len, int flags, const char *mbextra)
 {
-	return istrsenvisx(&mbdst, NULL, mbsrc, len, flags, mbextra, NULL);
+	return istrsenvisxna(mbdst, NULL, mbsrc, len, flags, mbextra, NULL);
 }
 
 int
 strsnvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags,
     const char *mbextra)
 {
-	return istrsenvisx(&mbdst, &dlen, mbsrc, len, flags, mbextra, NULL);
+	return istrsenvisxna(mbdst, &dlen, mbsrc, len, flags, mbextra, NULL);
 }
 
 int
 strsenvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags,
     const char *mbextra, int *cerr_ptr)
 {
-	return istrsenvisx(&mbdst, &dlen, mbsrc, len, flags, mbextra, cerr_ptr);
+	return istrsenvisxna(mbdst, &dlen, mbsrc, len, flags, mbextra, cerr_ptr);
 }
 
 /*
@@ -701,7 +711,7 @@ nvis(char *mbdst, size_t dlen, int c, int flags, int nextc)
 int
 strvis(char *mbdst, const char *mbsrc, int flags)
 {
-	return istrsenvisxl(&mbdst, NULL, mbsrc, flags, "", NULL);
+	return istrsenvisxl(mbdst, NULL, mbsrc, flags, "", NULL);
 }
 
 /*
@@ -721,14 +731,14 @@ strvis(char *mbdst, const char *mbsrc, int flags)
 int
 strnvis_openbsd(char *mbdst, const char *mbsrc, size_t dlen, int flags)
 {
-	return istrsenvisxl(&mbdst, &dlen, mbsrc, flags, "", NULL);
+	return istrsenvisxl(mbdst, &dlen, mbsrc, flags, "", NULL);
 }
 __asm__(".symver strnvis_openbsd,strnvis@@LIBBSD_0.2");
 
 int
 strnvis_netbsd(char *mbdst, size_t dlen, const char *mbsrc, int flags)
 {
-	return istrsenvisxl(&mbdst, &dlen, mbsrc, flags, "", NULL);
+	return istrsenvisxl(mbdst, &dlen, mbsrc, flags, "", NULL);
 }
 __asm__(".symver strnvis_netbsd,strnvis at LIBBSD_0.9.1");
 
@@ -736,7 +746,8 @@ int
 stravis(char **mbdstp, const char *mbsrc, int flags)
 {
 	*mbdstp = NULL;
-	return istrsenvisxl(mbdstp, NULL, mbsrc, flags, "", NULL);
+	return istrsenvisx(mbdstp, NULL, mbsrc,
+	    mbsrc != NULL ? strlen(mbsrc) : 0, flags, "", NULL);
 }
 
 /*
@@ -753,18 +764,18 @@ stravis(char **mbdstp, const char *mbsrc, int flags)
 int
 strvisx(char *mbdst, const char *mbsrc, size_t len, int flags)
 {
-	return istrsenvisx(&mbdst, NULL, mbsrc, len, flags, "", NULL);
+	return istrsenvisxna(mbdst, NULL, mbsrc, len, flags, "", NULL);
 }
 
 int
 strnvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags)
 {
-	return istrsenvisx(&mbdst, &dlen, mbsrc, len, flags, "", NULL);
+	return istrsenvisxna(mbdst, &dlen, mbsrc, len, flags, "", NULL);
 }
 
 int
 strenvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags,
     int *cerr_ptr)
 {
-	return istrsenvisx(&mbdst, &dlen, mbsrc, len, flags, "", cerr_ptr);
+	return istrsenvisxna(mbdst, &dlen, mbsrc, len, flags, "", cerr_ptr);
 }
commit 13c32916b4baab58d93940d57fea9ff0777f1931
Author: Baruch Siach <baruch at tkos.co.il>
Date:   Tue Jun 5 19:21:46 2018 +0300

    flopen: Add missing <fcntl.h> include
    
    Commit 993828d84ee (Add flopenat() function from FreeBSD) dropped the
    fcntl.h header. This breaks the build with musl libc:
    
    flopen.c: In function ‘vflopenat’:
    flopen.c:60:14: error: ‘O_CREAT’ undeclared (first use in this function)
      if (flags & O_CREAT) {
                  ^~~~~~~
    
    Restore the fcntl.h header include to fix the build.
    
    Fixes: commit 993828d84eed0468c6c15b2818e534e6b134b8e4
    Submitted-also-by: parazyd <parazyd at dyne.org>
    Signed-off-by: Baruch Siach <baruch at tkos.co.il>
    Signed-off-by: Guillem Jover <guillem at hadrons.org>

diff --git a/src/flopen.c b/src/flopen.c
index b9972c9..ff20d07 100644
--- a/src/flopen.c
+++ b/src/flopen.c
@@ -32,6 +32,7 @@
 #include <sys/stat.h>
 
 #include <errno.h>
+#include <fcntl.h>
 #include <stdarg.h>
 #include <unistd.h>
 


More information about the libbsd mailing list