bug-gnulib
[Top][All Lists]
Advanced

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

strerror: make C++ safe


From: Bruno Haible
Subject: strerror: make C++ safe
Date: Sat, 19 Nov 2016 14:09:46 +0100
User-agent: KMail/4.8.5 (Linux/3.8.0-44-generic; KDE/4.8.5; x86_64; ; )

When creating a gnulib testdir for module 'strerror'
  ./gnulib-tool --create-testdir --with-c++-tests --with-tests --dir=... 
strerror
and forcing REPLACE_STRERROR=1, the compilation in C++ mode with 
GNULIB_NAMESPACE
fails:

$ ./configure CPPFLAGS="-DGNULIB_NAMESPACE=gggg -Wall" CC=g++
$ make
...
g++ -DHAVE_CONFIG_H -I. -I..  -DGNULIB_STRICT_CHECKING=1 
-DGNULIB_NAMESPACE=gggg -Wall  -g -O2 -MT strerror.o -MD -MP -MF 
.deps/strerror.Tpo -c -o strerror.o strerror.c
strerror.c: In function 'char* rpl_strerror(int)':
strerror.c:70:35: error: invalid conversion from 'void*' to 'char*' 
[-fpermissive]
make[4]: *** [strerror.o] Error 1

The reason is that memcpy() returns a 'void *'. But we want a 'char *' here.
Rather than introduce a cast, simply use the known return value of memcpy().

I'm pushing this fix:


2016-11-19  Bruno Haible  <address@hidden>

        strerror: Make it compile in C++ mode.
        * lib/strerror.c (strerror): Ignore the return value of memcpy().

--- a/lib/strerror.c
+++ b/lib/strerror.c
@@ -66,5 +66,6 @@ strerror (int n)
   if (sizeof buf <= len)
     abort ();
 
-  return memcpy (buf, msg, len + 1);
+  memcpy (buf, msg, len + 1);
+  return buf;
 }




reply via email to

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