bug-gnulib
[Top][All Lists]
Advanced

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

wchar-h: Fix wcrtomb prototype conflict in C++ mode on OpenBSD 6.0


From: Bruno Haible
Subject: wchar-h: Fix wcrtomb prototype conflict in C++ mode on OpenBSD 6.0
Date: Sat, 28 Dec 2024 16:38:59 +0100

Compiling a testdir on OpenBSD 6.0, I get this compilation error:

../gllib/wchar.h: In member function 'gnulib::_gl_wcrtomb_wrapper::operator 
size_t (*)(char*, wchar_t, rpl_mbstate_t*)() const':
../gllib/wchar.h:1254: error: invalid conversion from 'size_t (*)(char*, 
wchar_t, mbstate_t*)' to 'size_t (*)(char*, wchar_t, rpl_mbstate_t*)'

It's not easy to fix this:
  - If I force REPLACE_MBSTATE_T to 0, I get 25 test failures, due to mbsinit()
    not working right and not being overridden.
  - If I let REPLACE_MBSTATE_T be 1 and mbstate_t gets overridden by a 32-bit
    type, wcrtomb() - which in _citrus_utf8_ctype_wcrtomb() accesses the second
    32-bit word of the mbstate_t - makes an out-of-bounds access.
  - So, the fix is to let REPLACE_MBSTATE_T be 1, but don't actually override
    mbstate_t. Like we already do on AIX.


2024-12-28  Bruno Haible  <bruno@clisp.org>

        wchar-h: Fix wcrtomb prototype conflict in C++ mode on OpenBSD 6.0.
        * lib/wchar.in.h (rpl_mbstate_t): Don't define on OpenBSD.

diff --git a/lib/wchar.in.h b/lib/wchar.in.h
index 1eaaf363f4..da475e01a4 100644
--- a/lib/wchar.in.h
+++ b/lib/wchar.in.h
@@ -198,11 +198,12 @@ typedef unsigned int rpl_wint_t;
 /* Override mbstate_t if it is too small.
    On IRIX 6.5, sizeof (mbstate_t) == 1, which is not sufficient for
    implementing mbrtowc for encodings like UTF-8.
-   On AIX and MSVC, mbrtowc needs to be overridden, but mbstate_t exists and is
-   large enough and overriding it would cause problems in C++ mode.  */
+   On AIX, MSVC, and OpenBSD 6.0, mbrtowc needs to be overridden, but
+   mbstate_t exists and is large enough and overriding it would cause problems
+   in C++ mode.  */
 #if !(((defined _WIN32 && !defined __CYGWIN__) || @HAVE_MBSINIT@) && 
@HAVE_MBRTOWC@) || @REPLACE_MBSTATE_T@
 # if !GNULIB_defined_mbstate_t
-#  if !(defined _AIX || defined _MSC_VER)
+#  if !(defined _AIX || defined _MSC_VER || defined __OpenBSD__)
 typedef int rpl_mbstate_t;
 #   undef mbstate_t
 #   define mbstate_t rpl_mbstate_t






reply via email to

[Prev in Thread] Current Thread [Next in Thread]