[Dovecot] comparing pointer to integer?

Timo Sirainen tss at iki.fi
Thu Aug 30 19:10:43 EEST 2007


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.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: This is a digitally signed message part
Url : http://dovecot.org/pipermail/dovecot/attachments/20070830/1afa3002/attachment.bin 


More information about the dovecot mailing list