[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [RFC] Simplify use of apr_hash_this()

From: Branko Cibej <brane_at_xbc.nu>
Date: Tue, 30 Jun 2009 18:47:29 +0200

Philip Martin wrote:
> Julian Foad <julianfoad_at_btopenworld.com> writes:
>
>> which is what we normally do, or add explicit type casts:
>>
>> for (hi = apr_hash_first(pool, entries); hi; hi = apr_hash_next(hi))
>> {
>> const char *item;
>> svn_wc_entry_t *entry;
>>
>> apr_hash_this(hi, (void *)&item, NULL, (void *)&entry);
>>
>> ...
>> }
>>
>
> I don't think that's valid, although it will work on most common
> platforms today. The problem is that in C a void* pointer can be
> bigger than any particular data pointer. When the compiler assigns
> to/from void* it adjusts for size as necessary, but the cast above
> defeats that. So inside apr_hash_this a void* value will get written
> into the space occupied by entry and that space might not be big
> enough.
>

Strictly speaking, no, it's not valid. And aliasing *might* break
if/when GCC does whole-program optimization. Neither is likely to cause
real problems, though.

-- Brane

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=2366770
Received on 2009-06-30 18:47:47 CEST

This is an archived mail posted to the Subversion Dev mailing list.