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

5 messages from 2008-08-07 to 2008-08-08. Participants: Robin H. Johnson, Brandon Casey, Junio C Hamano, Pierre Habouzit.
Thread: https://gitlist.dev/t/14879

## Robin H. Johnson, 2008-08-07 20:31

Subject: On PPC64, the parsing of integers on the commandline is bitshifted.
Message-ID: <20080807203122.GR22707@curie-int.orbis-terrarum.net>
URL: https://gitlist.dev/e/20080807203122.GR22707%40curie-int.orbis-terrarum.net

```
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, 2008-08-07 21:26

Subject: Re: On PPC64, the parsing of integers on the commandline is bitshifted.
Message-ID: <X68iwLodMeAo1RYVJdU3iyNzAFylpDRpP1jkviJTeiOnoNs5n2qZcg@cipher.nrlssc.navy.mil>
URL: https://gitlist.dev/e/X68iwLodMeAo1RYVJdU3iyNzAFylpDRpP1jkviJTeiOnoNs5n2qZcg%40cipher.nrlssc.navy.mil
In-Reply-To: <20080807203122.GR22707@curie-int.orbis-terrarum.net>

```
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, 2008-08-07 21:34

Subject: Re: On PPC64, the parsing of integers on the commandline is bitshifted.
Message-ID: <CxVxAoKmEQsrgFdHEvL0sjkgBBIVZ3Zvsl0pPSuDSfH_8xM8NOSGfw@cipher.nrlssc.navy.mil>
URL: https://gitlist.dev/e/CxVxAoKmEQsrgFdHEvL0sjkgBBIVZ3Zvsl0pPSuDSfH_8xM8NOSGfw%40cipher.nrlssc.navy.mil
In-Reply-To: <X68iwLodMeAo1RYVJdU3iyNzAFylpDRpP1jkviJTeiOnoNs5n2qZcg@cipher.nrlssc.navy.mil>

```
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.

-brandon

```

## Junio C Hamano, 2008-08-07 21:42

Subject: Re: On PPC64, the parsing of integers on the commandline is bitshifted.
Message-ID: <7vhc9wijsq.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vhc9wijsq.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <CxVxAoKmEQsrgFdHEvL0sjkgBBIVZ3Zvsl0pPSuDSfH_8xM8NOSGfw@cipher.nrlssc.navy.mil>

```
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().

```

## Pierre Habouzit, 2008-08-08 08:38

Subject: Re: On PPC64, the parsing of integers on the commandline is bitshifted.
Message-ID: <20080808083804.GB13578@artemis.madism.org>
URL: https://gitlist.dev/e/20080808083804.GB13578%40artemis.madism.org
In-Reply-To: <7vhc9wijsq.fsf@gitster.siamese.dyndns.org>

```
On Thu, Aug 07, 2008 at 09:42:29PM +0000, Junio C Hamano wrote:
> 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

```
