Re: [PATCH 1/6] Fix some "printf format" warnings.

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH 1/6] Fix some "printf format" warnings.

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:42:59

Simon 'corecode' Schubert [off-list ref] writes:
Ramsay Jones wrote:
quoted
quoted
quoted
-        printf("%s%06o %s %d\t",
+        printf("%s%06lo %s %d\t",
                tag,
                ntohl(ce->ce_mode),
I think we should do this instead:

    printf("%s%06o %s %d\t", tag, (unsigned) ntohl(ce->ce_mode), ...
Oops, yes you are right.
(cygwin typedef's uint32_t as unsigned long.)

However, I would hate to add all those casts! Casts are not always
evil, but should be avoided if possible. Having said that, I don't
see another solution ...
shouldn't it be something like this?

printf("%s%06"PRIo32" %s %d\t", tag, ntohl(ce->ce_mode), ...)

that's the correct and allegedly portable way I guess.
Yes, except that that is only portable across platforms with
inttypes.h, and we would need a compatibility definition in
git-compat-util.h next to PRIuMAX definition we already have.

But I wonder if this is really worth it.  The thing is,

    printf("%s%06o %s %d\t", tag, (unsigned) ntohl(ce->ce_mode), ...

is perfectly readable for even old timers about git, as long as
they know traditional C and what ntohl() is.  And ce->ce_mode
even fits in 16-bit, so while we are _not_ supporting platforms
whose unsigned int is 16-bit, the above cast is not losing any
useful precision either.

Re: [PATCH 1/6] Fix some "printf format" warnings.

From: Ramsay Jones <hidden>
Date: 2016-06-15 22:42:59

Junio C Hamano wrote:
Simon 'corecode' Schubert [off-list ref] writes:
quoted
Ramsay Jones wrote:
quoted
quoted
quoted
-        printf("%s%06o %s %d\t",
+        printf("%s%06lo %s %d\t",
                tag,
                ntohl(ce->ce_mode),
I think we should do this instead:

    printf("%s%06o %s %d\t", tag, (unsigned) ntohl(ce->ce_mode), ...
Oops, yes you are right.
(cygwin typedef's uint32_t as unsigned long.)

However, I would hate to add all those casts! Casts are not always
evil, but should be avoided if possible. Having said that, I don't
see another solution ...
shouldn't it be something like this?

printf("%s%06"PRIo32" %s %d\t", tag, ntohl(ce->ce_mode), ...)

that's the correct and allegedly portable way I guess.
Yes, except that that is only portable across platforms with
inttypes.h, and we would need a compatibility definition in
git-compat-util.h next to PRIuMAX definition we already have.
Hmmm, I only have the 1.5.0 code, and so I don't know what the
current code looks like; so if this is rubbish, please ignore...

In version 1.4.4, the only files to depend on <stdint.h> were
{arm,ppc}/sha1.[ch]. If this was a problem on any given arm/ppc
platform, you could configure the software to use the OpenSSL
or Mozilla versions instead.

In 1.5.0, however, git-compat-util.h _unconditionally_ includes
<inttypes.h>, which in turn includes <stdint.h>. Now the files
which depend on definitions in <stdint.h> includes:
    {arm,ppc}/sha1.[ch]
    cache.h
    pack.h
    builtin-pack-objects.c
    fast-import.c
    sha1_file.c
(the symbols being: uint32_t, uint64_t, uint16_t, uintmax_t)
Version 1.5.0 does not seem to depend on any symbols in the
<inttypes.h> header file...

So, at least for 1.5.0, those header files are already
required.

I don't know if that is desired ;-)

ATB,

Ramsay Jones
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help