threads / discuss / 14879

On PPC64, the parsing of integers on the commandline is bitshifted.

Subject: On PPC64, the parsing of integers on the commandline is bitshifted.

## tl;dr

5 messages between Aug 7, 2008 and Aug 8, 2008.

replies: 4people: 4as markdown or json

Robin H. Johnson· Aug 7, 2008, 20:31 UTC · lore

In a 64-bit userland, big-endian environment, the parser gets integers wrong.

# ./test-parse-options --set23 |grep integer integer: 98784247808 # patch ... # ./test-parse-options --set23 |grep integer integer: 23

Full failures from the testcases -integer: 1729 +integer: 7425998454784 -integer: 13 +integer: 55834574848 -integer: 2 +integer: 8589934592 -integer: 23 +integer: 98784247808

All the values are shifted up 32 bits.
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>

--- Please CC me in replies, I'm not on git@vger.

Fix against 1.5.6.4: --- parse-options.c.orig 2008-08-07 14:51:17.000000000 -0500 +++ parse-options.c 2008-08-07 14:51:25.000000000 -0500

@@ -78,7 +78,7 @@
 		return 0;
 
 	case OPTION_SET_INT:
-		*(int *)opt->value = unset ? 0 : opt->defval;
+		*(long int *)opt->value = unset ? 0 : opt->defval;
 		return 0;
 
 	case OPTION_SET_PTR:
-- 
Robin Hugh Johnson
Gentoo Linux Developer & Infra Guy
E-Mail     : robbat2@gentoo.org
GnuPG FP   : 11AC BA4F 4778 E3F6 E4ED  F38E B27B 944E 3488 4E85
Brandon Casey· Aug 7, 2008, 21:26 UTC · re: Robin H. Johnson · lore

Re: On PPC64, the parsing of integers on the commandline is bitshifted.

Robin H. Johnson wrote:
> In a 64-bit userland, big-endian environment, the parser gets integers
> wrong.

There is a fix on master. Can you try that out? Unfortunately, looks like it did not make it into 1.5.6.5

-brandon
Brandon Casey· Aug 7, 2008, 21:34 UTC · re: Brandon Casey · lore

Re: On PPC64, the parsing of integers on the commandline is bitshifted.

Brandon Casey wrote:
Show 6 quoted lines
> Robin H. Johnson wrote:
>> In a 64-bit userland, big-endian environment, the parser gets integers
>> wrong.
> 
> There is a fix on master. Can you try that out?
> Unfortunately, looks like it did not make it into 1.5.6.5

Also, just so you know, it is test-parse-options.c that is broken, not the parsing code. So, the rest of git should be using an int with OPT_INTEGER() and should operate correctly.

-brandon
Junio C Hamano· Aug 7, 2008, 21:42 UTC · re: Brandon Casey · lore

Re: On PPC64, the parsing of integers on the commandline is bitshifted.

Brandon Casey <casey@nrlssc.navy.mil> writes:
Show 11 quoted lines
> Brandon Casey wrote:
>> Robin H. Johnson wrote:
>>> In a 64-bit userland, big-endian environment, the parser gets integers
>>> wrong.
>> 
>> There is a fix on master. Can you try that out?
>> Unfortunately, looks like it did not make it into 1.5.6.5
>
> Also, just so you know, it is test-parse-options.c that is broken, not
> the parsing code. So, the rest of git should be using an int with
> OPT_INTEGER() and should operate correctly.

Yup, that is why it is not on 'maint' --- but somebody should audit the parse_options() users in the real programs to make sure that there is no similar breakages, namely, giving a pointer to long to OPT_INTEGER().

Pierre Habouzit· Aug 8, 2008, 08:38 UTC · re: Junio C Hamano · lore

Re: On PPC64, the parsing of integers on the commandline is bitshifted.

On Thu, Aug 07, 2008 at 09:42:29PM +0000, Junio C Hamano wrote:
Show 17 quoted lines
> Brandon Casey <casey@nrlssc.navy.mil> writes:
> 
> > Brandon Casey wrote:
> >> Robin H. Johnson wrote:
> >>> In a 64-bit userland, big-endian environment, the parser gets integers
> >>> wrong.
> >> 
> >> There is a fix on master. Can you try that out?
> >> Unfortunately, looks like it did not make it into 1.5.6.5
> >
> > Also, just so you know, it is test-parse-options.c that is broken, not
> > the parsing code. So, the rest of git should be using an int with
> > OPT_INTEGER() and should operate correctly.
> 
> Yup, that is why it is not on 'maint' --- but somebody should audit the
> parse_options() users in the real programs to make sure that there is no
> similar breakages, namely, giving a pointer to long to OPT_INTEGER().
  Well FWIW I'll probably write some __GNUC__ guarded glue using
__builtin_types_compatible and friends to ensure we're not passing crap
to the OPT_* macros. I just didn't have time to yet.
-- 
·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                http://www.madism.org

← back to recent threads