[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] bounds checking

From: Christian Jullien
Subject: Re: [Tinycc-devel] bounds checking
Date: Wed, 11 Dec 2019 07:24:31 +0100

 va_list, as used by printf, holds information about variable arguments.
 It is implementation dependant. It loses types and sizes of arguments it

 The purpose of format directive is to collect the right object size and
 coerce this shunk of bytes into the expected type.

 On ARM (32bits), long long is implemented internally using two 32bits machine

 Current code only extends the print precision of long but does not collect
 long long.

 I don't know the purpose of bounds_check1_test but your proposal, in case
 of pv(x), coerces an int to long long which will of course work.

 To keep the spirit of initial code it must be:

 #define pv(m) printf(sizeof (s->m + 0) == 8 ? "%llx\n" : "%x\n", s->m)

 I let the writer of this test choose what to do.

 Below this snippet shows that only the format directive is faulty, not the 

Both tcc and gcc output:
sizeof(l) = 4
sizeof(ll) = 8
l: 12345678 ffffffff
l: 12345678 ffffffff
ll: 0 34567890
ll: 0 34567890
ll: 1234567890 ffffffff

#include <stdio.h>
#include <stdlib.h>

main() {
        unsigned long l = 0x12345678;
        unsigned long long ll = 0x1234567890;
        unsigned guard = ~0;

        printf("sizeof(l) = %lu\n", sizeof(l));
        printf("sizeof(ll) = %lu\n", sizeof(ll));

        printf("l: %x %x\n", l, guard);
        printf("l: %lx %x\n", l, guard);

        printf("ll: %x %x\n", ll, guard);   // truncated
        printf("ll: %lx %x\n", ll, guard);  // truncated
        printf("ll: %llx %x\n", ll, guard); // OK


-----Original Message-----
From: Tinycc-devel [mailto:tinycc-devel-bounces+eligis=address@hidden] On 
Behalf Of Edmund Grimley Evans
Sent: Tuesday, December 10, 2019 23:15
To: address@hidden
Subject: Re: [Tinycc-devel] bounds checking

> #define pv(m) printf(sizeof (s->m + 0) == 8 ? "%llx\n" : "%x\n", s->m)

What's wrong with printf("%llx\n", (unsigned long long)s->m)?

Tinycc-devel mailing list

reply via email to

[Prev in Thread] Current Thread [Next in Thread]