[Dovecot] comparing pointer to integer?
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) {
There are a lot of occurences for these in the source. GCC only warns
because of this, but DEC C is known to consider this an error:
Error: file-cache.c, line 79: In this statement, "new_base" and
"(-1)" may not be compared for equality or inequality.
if (new_base == MAP_FAILED) {
And indeed, unsigned integers and -1 are rarely equal.
-- Gabucino
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.
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.
On 2007-08-31 15:45:26 +0200, Bérczi Gábor (Gabucino) wrote:
On Digital Unix V4.0B, it is:
/usr/include/sys/mman.h:#define MAP_FAILED (-1L) /*
unsuccessful return from mmap() */
arent you the same guy who bothered lighttpd devs for fixing it for that old unix?
v4.0b is from 1996. i am not sure it is worth to support it.
darix
-- openSUSE - SUSE Linux is my linux openSUSE is good for you www.opensuse.org
On Aug 31, 2007, at 5:53 PM, Marcus Rueckert wrote:
v4.0b is from 1996. i am not sure it is worth to support it.
Considering that for me it's a significantly better UNIX than:
openSUSE - SUSE Linux is my linux openSUSE is good for you www.opensuse.org
...in 2007, therefore I concur. But whatever. I already use dovecot
on it for 2 years, I just wondered if upstream is interested in out-
of-the-box compilation. But if that's a "bother", then it's fine for me.
participants (3)
-
"Bérczi Gábor (Gabucino)"
-
Marcus Rueckert
-
Timo Sirainen