[Top][All Lists]

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

[bug-gnulib] Re: [PATCH]: fix warning in the hash module

From: Ian Abbott
Subject: [bug-gnulib] Re: [PATCH]: fix warning in the hash module
Date: Thu, 19 May 2005 10:47:29 +0100
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

On 18/05/2005 19:29, Yoann Vandoorselaere wrote:
On Wed, 2005-05-18 at 16:16 +0100, Ian Abbott wrote:

On 17/05/2005 10:20, Yoann Vandoorselaere wrote:

However, I still consider this version of the patch to be a hack, when
the real bug here is that you should not use const since you permit the
user to free() the data from the interface callback. The interface
should not use const at all.

Can you show how the Hash_data_freer callback is called from hash_insert, because I can't see it!

It is not. The point was that the interface allow the user to specify a
callback for freeing the data, and thus the pointer to theses data
should not be marked as const.

In that case, I agree with Jim that the current prototype declaration is correct. The function does not modify the data through the pointer, hence the thing it is pointing to should be declared const within the function.

There is an unavoidable removal of the const qualifier because the function returns a non-const qualified pointer to the const qulaified data (similar to strstr). That could be avoided by making the function return a 'const void *', but that would be the wrong thing to do, as the caller might want to modify the data and would have to cast away the const qualifier itself to do that.

Your workaround using a union would hide the warning about removal of the qualifier. Whether or not it is worth implementing is a matter of opinion. Presumably, the same sort of trick would have to be done in gnulib's strstr implementation and similar functions too.

-=( Ian Abbott @ MEV Ltd.    E-mail: <address@hidden>        )=-
-=( Tel: +44 (0)161 477 1898   FAX: +44 (0)161 718 3587         )=-

reply via email to

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