• Subject: Re: Test a packed number for validity - code included
  • From: bmorris@xxxxxxxxxx
  • Date: Fri, 19 Jan 2001 10:42:36 -0500
  • Importance: Normal


Date: Thu, 18 Jan 2001 17:21:17 -0500
From: Buck Calabro <buck.calabro@aptissoftware.com>

Buck, it's good except for one bug: if you have an options(*varsize)
parameter, you have to substring it if you want to copy it.  By
copying the whole parameter to wrkChar, you're almost always copying
more data than you were passed, and you run the risk of an occasional
hard MCH0601 error (pointer-offset).

Oops!  Two bugs.  CEEGSI requires an additional parameter which is
omissible (meaning you can pass *OMIT, but not meaning it's
optional).  Code it as 12A OPTIONS(*OMIT) and pass *OMIT if
you want to omit it.  You can get very strange seemingly random
and unrelated storage-corruption bugs by leaving out omissible
parameters.  (Sometimes the bugs don't manifest themselves until
long after your procedure has returned.  If you're lucky, you get
a nice loud pointer-not-set error right after the call, but it's
rare to be so lucky.)

Your procedure can be simplified (and corrected) by using VARYING
instead of OPTIONS(*VARSIZE) for the parameter.  (I see you are
using indicators (N), so I know you are on a version that allows
VARYING.)

With VARYING, you don't need to call an API to get the length of
the passed parameter.  You can just use %len.

If you make the change to using VARYING, be careful with %addr;
%addr of a varying field includes the 2 bytes at the beginning.
An alternative prototype for cvthc would allow you to skip
the wrkChar temporary and allow you to pass both varying and
fixed length character parameters.

     d H2C             pr                  extProc('cvthc')
     d   tgt                           *   value
     d   src                      32767A   const options(*varsize)
     d   tgtlen                      10I 0 value

if inpChar is VARYING:
     c                   callp     H2C(%addr(outChar) :
     c                                 inpChar :
     c                                 %len(inpChar) * 2)

or, if you keep inpChar as options(*varsize):

     c                   callp     H2C(%addr(outChar) :
     c                                 %subst(inpChar:1:currLen) :
     c                                 currLen * 2)

Barbara Morris


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

As an Amazon Associate we earn from qualifying purchases.

This thread ...


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

This mailing list archive is Copyright 1997-2024 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].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.