rdmenezes / wvstreams

Automatically exported from code.google.com/p/wvstreams
0 stars 0 forks source link

Compilation of 4.3 (and current svn) is broken on machines with 64bit address #9

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Get wvstreams-4.3 or svn.
2. Try to compile on any x86_64 or other 64-bit address architecture (I
have tried with gcc 4.1.2).
3. Compilation fails.

utils/wvcrash.cc: In function ‘void wra(int, const void*)’:
utils/wvcrash.cc:95: error: cast from ‘const void*’ to ‘unsigned int’
loses precision

Part of code with problem (around utils/wvcrash.cc:95):

// convert 'addr' to hex and write it to fd.
static void wra(int fd, const void *addr)
{
    char digits[] = "0123456789ABCDEF";

    write(fd, "0x", 2);
    for (int shift=28; shift>=0; shift-=4)
        write(fd, &digits[(((unsigned)addr)>>shift)&0xF], 1);
}

Original issue reported on code.google.com by sstas...@gmail.com on 9 Mar 2007 at 9:50

GoogleCodeExporter commented 9 years ago
Cross platform code should use either system function to print address or use
ptrdiff_t (from malloc.h) or similar type.

Working test:

#include <unistd.h>
#include <malloc.h>

static void wra(int fd, const void *addr)
{
    const unsigned int ptrbitsshift = (sizeof(ptrdiff_t) << 3) - 4;
    char digits[] = "0123456789ABCDEF";

    write(fd, "0x", 2);
    for (int shift=ptrbitsshift; shift>=0; shift-=4)
        write(fd, &digits[(((ptrdiff_t)addr)>>shift)&0xF], 1);
}   

int main(int argc, char** argv) {
    int c = '\n';
    wra(1, &c);
    write(1, &c, 1);
}

Original comment by sstas...@gmail.com on 9 Mar 2007 at 10:34

GoogleCodeExporter commented 9 years ago
Seems reasonable to me. Care to attach a full patch which makes wvstreams 
compile on
your system? I'd be more than happy to apply it.

Original comment by wrl...@gmail.com on 16 Mar 2007 at 7:08

GoogleCodeExporter commented 9 years ago
Ah, I see, wra is basically a replacement for a function in wvcrash.cc. Looks
reasonable, let's commit.

Original comment by wrl...@gmail.com on 2 Jul 2007 at 8:28