From owner-freebsd-questions@FreeBSD.ORG Sat Sep 12 10:56:21 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4BB931065670 for ; Sat, 12 Sep 2009 10:56:21 +0000 (UTC) (envelope-from freebsd-listen@fabiankeil.de) Received: from smtprelay02.ispgateway.de (smtprelay02.ispgateway.de [80.67.31.25]) by mx1.freebsd.org (Postfix) with ESMTP id C99CF8FC08 for ; Sat, 12 Sep 2009 10:56:20 +0000 (UTC) Received: from [62.143.132.83] (helo=r500.local) by smtprelay02.ispgateway.de with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.68) (envelope-from ) id 1MmQ34-0006X3-GA for freebsd-questions@freebsd.org; Sat, 12 Sep 2009 12:41:42 +0200 Date: Sat, 12 Sep 2009 12:41:43 +0200 From: Fabian Keil To: freebsd-questions@freebsd.org Message-ID: <20090912124143.2fb77924@r500.local> In-Reply-To: <53480375@bb.ipt.ru> References: <53480375@bb.ipt.ru> X-Mailer: Claws Mail 3.7.2 (GTK+ 2.16.6; amd64-portbld-freebsd9.0) X-PGP-KEY-URL: http://www.fabiankeil.de/gpg-keys/freebsd-listen-2008-08-18.asc Mime-Version: 1.0 Content-Type: multipart/signed; micalg=PGP-SHA1; boundary="Sig_/WpX7GCjjFSCWRecuUCZyX20"; protocol="application/pgp-signature" X-Df-Sender: 775067 Subject: Re: c++: invalid conversion from 'int' to 'const char*' X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Sep 2009 10:56:21 -0000 --Sig_/WpX7GCjjFSCWRecuUCZyX20 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Boris Samorodov wrote: > I'm porting a c++ application to FreeBSD. I've got an error: > ----- > ~/work/src/FileChannel.cpp: In member function 'QString FileChannel::erro= rString()': > ~/work/src/FileChannel.cpp:251: error: invalid conversion from 'int' to '= const char*' > ~/work/src/FileChannel.cpp:251: error: initializing argument 2 of 'char= * strcpy(char*, const char*)' > *** Error code 1 > ----- >=20 > A simle patch makes the application to be compiled without errors: > ----- > --- src/FileChannel.cpp.orig 2009-09-12 13:08:28.000000000 +0400 > +++ src/FileChannel.cpp 2009-09-12 13:08:41.000000000 +0400 > @@ -248,7 +248,7 @@ > =20 > QString FileChannel::errorString() > { > - strcpy(lastErrorString, strerror_r(errno, lastErrorString, 0)); > + strcpy(lastErrorString, "XXX: Fix me: errno should be here"); > return QString(trUtf8(lastErrorString)); > } At least to me, this looks like a bug in the program you are porting. I don't see how this would work on other platforms either, unless the libc strerror_r() is shadowed which seems unlikely. I assume someone replaced strerror() with strerror_r() and missed the differences. The third argument of strerror_r() being zero looks strange, too. > If I understand correctly, an integer value which is returned by > strerror_r() should be converted to const char*. > > I have _very_ basic knowledge about c++. Hence my question. > Can someone provide a patch (a proof of concept)? Thanks! You could try replacing the strerror_r() call with strerror(errno). It wouldn't be thread-safe, but should at least work most of the time. If the application is threaded, a better fix would be not to use strcpy() at all. strerror_r() already puts the error description into the buffer, so there's no need to copy anything. To do this, you'd still need to fix the third argument, though. If lastErrorString is an array you could use sizeof(lastErrorString), if it's a pointer you could look for a malloc() call that allocates the buffer to figure out the size. Either way, you should probably report the problem upstream. Fabian --Sig_/WpX7GCjjFSCWRecuUCZyX20 Content-Type: application/pgp-signature; name=signature.asc Content-Disposition: attachment; filename=signature.asc -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.13 (FreeBSD) iEYEARECAAYFAkqreusACgkQBYqIVf93VJ2gGwCgymOxY2JMIipmzfIqNzk4ugDS XusAnRmuAOnSHB9SqjeG5U8ll2vRVMpL =IhPz -----END PGP SIGNATURE----- --Sig_/WpX7GCjjFSCWRecuUCZyX20--