Re: building with gcc 4.4
Sam Varshavchik <[email protected]> Sun, 19 Apr 2009 07:56:23 -0400
| Newsgroups | gmane.mail.cone |
|---|---|
| Message-ID | <[email protected]> |
Milos Jakubicek writes:
> Hi Sam,
>
> Sam Varshavchik wrote:
>> Milos Jakubicek writes:
>>
>>> Hi all,
>>>
>>> I'm attaching a tiny patch to make cone building with gcc 4.4, please
>>> merge it.
>>
>> Although this looks very straightforward, I do have some questions.
>> AFAIK, SUSv2 explicitly defines strchr as taking a const char * arg. The
>> cast should not be necessary.
>
> Yes, the problem is that starting with gcc 4.4, if strchr takes const
> char*, it also returns const char*, therefore the cast.
> See http://gcc.gnu.org/gcc-4.4/porting_to.html
I see. In that case, the correct fix is really to redeclare the "p" pointer
as a const char *, rather than casting it.
> Furthermore, a quick search of the code finds several other
>> instances where both strchr() and memcpy() are used with the same
>> parameter types, so if these two instances need this kind of a patch,
>> how come the other instances don't?
>
> What places, aren't they in an #ifdef so that they do not evaluate?
> Remember that the problem is again the same: you give const char* to
> strchr => it returns const char*. I'm not sure whether the standard says
> you can cast any pointer type, even const type, to void*.
That actually explains it. The memcpy in question takes the return value
from strrchr() with itself takes a const char * parameter, which now makes
the memcpy parameter a const char *.
The correct fix there, then, would be to const_cast the strrchr() parameter
to a char *.
Can you verify that the following will make gcc 4.4 happy.
Index: libmail/maildiradd.C
===================================================================
RCS file: /cvsroot/courier/libs/libmail/maildiradd.C,v
retrieving revision 1.6
diff -U3 -r1.6 maildiradd.C
--- libmail/maildiradd.C 24 May 2008 17:57:42 -0000 1.6
+++ libmail/maildiradd.C 19 Apr 2009 11:54:45 -0000
@@ -165,7 +165,8 @@
if (flags.size() > 0)
{
newname = newname + MDIRSEP "2," + flags;
- memcpy(strrchr(newname.c_str(), '/')-3, "cur", 3);
+ memcpy(strrchr(const_cast<char *>(newname.c_str()), '/')-3,
+ "cur", 3);
// We go into the cur directory, now
}
Index: libmail/qp.C
===================================================================
RCS file: /cvsroot/courier/libs/libmail/qp.C,v
retrieving revision 1.1
diff -U3 -r1.1 qp.C
--- libmail/qp.C 27 May 2003 14:09:08 -0000 1.1
+++ libmail/qp.C 19 Apr 2009 11:54:46 -0000
@@ -16,7 +16,7 @@
{
static const char xdigits[]="0123456789ABCDEFabcdef";
- char *p=strchr(xdigits, c);
+ const char *p=strchr(xdigits, c);
if (p == NULL)
return -1;
------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today.
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
Courier-cone mailing list
[email protected]
Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-cone
signature.asc
(application/pgp-signature, 197 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEABECAAYFAknrEWcACgkQx9p3GYHlUOLI7wCeMomqosprdmQQ6a+OiJ2qXzVE aVIAn0+IMIhrGFbUz0qOMayGof/YCd5a =j25l -----END PGP SIGNATURE-----