Strange sorting

Anthony Dardis adardis at gmail.com
Thu Oct 7 10:21:52 EDT 2010


Got it. What strikes me as non-trivial is using strtol(x, NULL, 0) rather  
than strtol(x, NULL, 10). atoi doesn't do this intepretation.

strtol with **endp = NULL throws away what comes after the convertable  
numerals, so what if someone has num values, say, 100a and 100b?

On Thu, 07 Oct 2010 09:25:10 -0400, Derek Atkins <warlord at mit.edu> wrote:

> "Anthony Dardis" <adardis at gmail.com> writes:
>
>> Speaking as an old young programmer, seems like it would be
>> non-trivial for the "interpret as octal" hook to grab onto the
>> transaction number  field, since it appears to be a string. But stuff
>> happens.
>
> I don't understand why you think this is non-trivial.  The 'order'
> function has the following code in it:
>
>     /* otherwise, sort on number string */
>     na = atoi(ta->num);
>     nb = atoi(tb->num);
>     if (na < nb) return -1;
>     if (na > nb) return +1;
>
> The problem is that the "convert string to number" function that was
> used had an implicit "leading zero means interpret as octal" side-effect
> (I believe it was using effectively strtol(x, NULL, 0)).  The code
> currently uses atoi() which should explicitly be decimal, but perhaps we
> should change it to an explicit strtol(ta->num, NULL, 10).  Regardless,
> any change will not go into the never-being-touched-again 2.2 branch,
> because we don't plan on a 2.2.10 release.
>
> -derek


More information about the gnucash-user mailing list