On 26/02/09 16:38, John Scoles wrote:
Could be.

I have established that, on my platform (SUSE 10 x86-64) there is a
real potential for wrong output. The program

#include <stdio.h>
int main(){printf("%ld %ld %ld %ld %ld %ld\n",1, -1,1,-1,1,-1);return 0;}

outputs

1 4294967295 1 4294967295 1 140737488355327

when compiled with the default (-m64) 64-bit environment.

The question is will converting these to to 64bit cause problems on 32bit platforms??

I am not proposing to convert to 64 bit, but to type long.

For example, on 32-bit x86, int and long are both 32 bit types.
On such a platform, the new compiler warnings will appear, but
the output will be correct, as no actual conversion is
necessary. The casts I am proposing to add will have no effect
(except to remove the compiler warnings) for the same reason.

On x86-64, int is a 32-bit type and long is a 64-bit type.
Without the casts there may be incorrect output. With the
casts there won't be.

I do not have a 64bit box myself so I cannot test this.

I will do some testing.

If there is no danger then go ahead and patch and I will put it in the next release candidate RC4

OK. I have downloaded RC3, and will try to get a patch out today.


Charles Jardine wrote:
I have built a 64 bit version of Perl 5.10.0 under SLES 10 (x86-64).
I am now installing DBI and DBD::Oracle.

Both of these modules produce alarming warnings at compile time.
E.g.

DBI.xs: In function ‘dbih_setup_fbav’:
DBI.xs:1549: warning: format ‘%ld’ expects type ‘long int’, but argument 3 has type ‘int’

I have pasted a transcript of the DBI compilation below. The DBD::Oracle
warnings are similar, but more numerous.

I have looked at the source, and it seems to me that these warnings
are genuine. 32 bit integers are being passed to PerlIO_printf
where the format requires 64 bits. This is incorrect C. The effects
will be architecture dependent, and may include incorrect output and
even core dumps.

That said, the modules pass their tests and seem to work. However,
the incorrect code is mostly only exercised when tracing is turned on.

I wondered why I had never seen this before. It turns out that
Perl 5.10.0 has an improvement in this area. For gcc, the
declaration of PerlIO_printf has been enhanced by the addition
of '__attribute__((format(__printf__,2,3)))'. This, for the
first time, allows gcc to check the types of PerlIO_printf's arguments.

Do others agree with me that these format errors constitute a bug
which needs fixing? If so I will attempt a patch.

In the meanwhile I will retreat to a 32 bit perl.

Reply via email to