• Subject: Re: asdbget - precision
  • From: "Jason M. Felice" <jasonf@xxxxxxxxxxxxxx>
  • Date: Fri, 17 Mar 2000 10:11:49 -0500

On Thu, Mar 16, 2000 at 06:03:46PM -0500, Sean Porterfield wrote:
> Sean Porterfield wrote:
> 
> > Response at end...
> >
> > "Jason M. Felice" wrote:
> >
> > > On Wed, Mar 15, 2000 at 05:20:28PM -0500, Sean Porterfield wrote:
> > > > Toward the end of this function, what is the purpose of "v = -v;" ?
> > > > It's what is causing my precision to show as negative on some fields in
> > > > my XML (I haven't yet found a pattern or reason).  Before I just comment
> > > > it out, I wanted to see if it had a purpose.  It may well be indicitive
> > > > of a hidden bug somewhere, of a misunderstanding due to OS400 version
> > > > differences.
> > > >
> > > > (I'm on V4R2)
> > > >
> > > > /* Convert a signed decimal field to a C `int' */
> > > > static int
> > > > signed2int (buf, len)
> > > >         Byte *buf;
> > > >         int len;
> > > > {
> > > >   int v = 0;
> > > >   while (len)
> > > >     {
> > > >       v *= 10;
> > > >       v += buf[0] & 0x0f;
> > > >       len--;
> > > >       buf++;
> > > >     }
> > > >   if ((buf[0] & 0xf0) == 0xd0)
> > > >     v = -v;
> > > >   return v;
> > > > }
> > >
> > > This converts an AS/400 signed field to an integer (we should probably be
> > > converting to a long, but that doesn't matter on 32-bit architectures).  
>This
> > > is IBM's zoned-decimal format, which stores one digit per byte and 
>zone-shifts
> > > the last digit if the field is negative.
> > >
> > > Basically, ebcdic digits zero through nine are X'F0' - X'F9', but the last
> > > digit is converted to X'D0' - X'D9' for a negative number.
> > >
> > > However, looking over it for the fifth time, the function is in error.  
>Try
> > > this instead:
> > >
> > > /* Convert a signed decimal field to a C `int' */
> > > static int
> > > signed2int (buf, len)
> > >         Byte *buf;
> > >         int len;
> > > {
> > >   int v = 0;
> > >   while (len)
> > >     {
> > >       v *= 10;
> > >       v += buf[0] & 0x0f;
> > >       len--;
> > >       if (--len == 0 && (buf[0] & 0xf0) == 0xd0)
> > >         v = -v;
> > >       buf++;
> > >     }
> > >   return v;
> > > }
> > >
> > > It seems we were checking the zone of a random garbage character (the 
>first
> > > character after the end of the field).  I've just fixed this in CVS.
> > >
> > > -Jay 'Eraserhead' Felice
> > >
> >
> > CVS code doesn't have the len--; line in it.  When I keyed exactly as you 
>have it
> > here, I got a seg fault/core dump when it was "RETR QTEMP/FIELDS"
> >
> > Using the code from CVS does not cause the crash.  I haven't checked for 
>any other
> > problems yet.
> 
> Well, it doesn't crash that way, but it does still show negative numbers on my
> precision in some fields.
> 
> argh!

Is the precision correct other than the sign?  I would suspect that it's
not, most likely because the field is in a different place from where it should
be according to the hard-coded position in asdbget.

> 
> 

-Jay 'Eraserhead' Felice
+---
| This is the LINUX5250 Mailing List!
| To submit a new message, send your mail to LINUX5250@midrange.com.
| To subscribe to this list send email to LINUX5250-SUB@midrange.com.
| To unsubscribe from this list send email to LINUX5250-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2020 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].