[Dovecot] comparing pointer to integer?

Bérczi Gábor (Gabucino) gabor at berczi.be
Fri Aug 31 16:45:26 EEST 2007


On Digital Unix V4.0B, it is:

/usr/include/sys/mman.h:#define MAP_FAILED      (-1L)   /*  
unsuccessful return from mmap() */

On Aug 30, 2007, at 6:10 PM, Timo Sirainen wrote:

> On 30.8.2007, at 15.49, Bérczi Gábor (Gabucino) wrote:
>
>> For example in src/lib/file-cache.c:
>>
>> if (cache->mmap_base == MAP_FAILED) {
>>
>> Should be fixed, probably like this:
>>
>> if ((int)cache->mmap_base == MAP_FAILED) {
>
> No. MAP_FAILED is supposed to be a pointer. For example in Linux:
>
> /usr/include/sys/mman.h:#define MAP_FAILED      ((void *) -1)
>
> And in any case you really don't want to cast it to int, rather  
> ssize_t so that it won't break with 64bit systems.
>
>> And indeed, unsigned integers and -1 are rarely equal.
>
> Not really, Dovecot does such comparisons a lot. :)
>
> Casting an unsigned integer to signed where the original value  
> doesn't fit to the destination is undefined by ANSI C. Casting a  
> signed integer to unsigned integer however is valid. (unsigned  
> int)-1 means the largest value that the unsigned int can hold. So  
> comparing unsigned int to -1 means comparing it to the largest value.
>



More information about the dovecot mailing list