Home > AS/400 Tips > iSeries programmer tips > Space violation mystery solved
iSeries 400 Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ISERIES PROGRAMMER TIPS

Space violation mystery solved


John Blenkinsop
12.01.2004
Rating: -4.44- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


Ever had this problem? If you haven't yet, you may in the future, so read carefully . . .

A procedure falls over with a space violation error, but no pointers to objects are being altered where the error occurs. The error is on an EVAL statement which looks like this:

Eval  g_ListEntryPtr =
      g_ListSpacePtr +
      g_ListOffset   -
      g_EntrySize    +
     (g_EntrySize * g_EntryNum)

g_ListSpacePtr is a space pointer addressing the start of a User Space, and the other terms are scalar (i.e. 'just numbers'). The receiving variable g_ListEntryPtr is another pointer variable, but it is not addressing anything. All variables are global (hence the 'g_' prefix) and may be referenced in other procedures in the same module (p_UsrSpc).

More Information

So, what is happening here for an error to occur?

In the EVAL statement, the value obtained after each term is evaluated will be stored in a compiler-supplied intermediate (working) variable.

The evaluation proceeds thus:

Step 1: Evaluate terms in parentheses

(g_EntrySize * g_EntryNum) = 1070 * 1 = 1070

(This result is stored in an internal compiler variable of scalar type.)

Step 2: Evaluate in order left to right

a) g_ListSpacePtr + g_ListOffset = [address] + 260 = [new address]

(This result is stored in an internal compiler variable of POINTER type.)

b) - g_EntrySize = [new address] – 1070 = [newer address]

(This result is stored in the SAME internal pointer variable as before.)

At this point the program fails, because when the compiler created the internal pointer variable, it created it so that it pointed to the object addressed by pointer g_ListSpacePtr. Since the internal variable's value is LESS THAN the value that is the actual base address of the object, the system determines that an address error (space violation) has taken place.

How do we get around this?

By re-arranging the arithmetic, we can prevent the address from being made effectively 'negative' with respect to the start of the addressed object:

Eval  g_ListEntryPtr =
      g_ListSpacePtr + 
      g_ListOffset   + 
     (g_EntrySize * g_EntryNum) -
      g_EntrySize 

As you see, the subtraction is now at the end of the set of terms and will be evaluated last. Another way would be to put ALL the non-pointer terms into parentheses so that the intermediate results would not be applied to the pointer variable until all their evaluations were complete:

Eval  g_ListEntryPtr =
      g_ListSpacePtr +
      ( g_ListOffset + (g_EntrySize * g_EntryNum) - g_EntrySize )

Of course, a better way would be for IBM to STOP allowing compiler-created internal variables to become involved in object addressing!

---------------------------
About the author: John Blenkinsop is a senior programmer at NYK Logistics & Megacarrier in London, and he is a site expert on Search400.com.


Rate this Tip
To rate tips, you must be a member of Search400.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
iSeries CL programming
Taking advantage of CL advancements, starting with V5R3
Checking in on your IBM i authorization lists
Running PHP open source applications: NOBODY needs authority
Simplify the process of converting a spool file from iSeries into an Excel spreadsheet
CL program for daily backups
An automated CL method of moving a query from AS/400 to Excel
Changing user password expiration
Eight steps for creating program documentation using AS/400 utilities
DAYSPAST CLLE program for AS/400: Compares object creation date with today's date
Advanced Job Scheduler help

iSeries programmer tips
Enhancing RPG with external SQL stored procedures
Tracking data changes on IBM i with triggers
Introduction to SQLRPGLE on IBM i: Making a report
Implementing a browser interface in COBOL: Displaying database fields
Taking advantage of CL advancements, starting with V5R3
TAATOOL: Useful tools for programmers on IBM i
Implementing a browser interface in COBOL: Creating your graphic Web page
Implementing a browser interface in COBOL: Getting started
Making the most of RPG data handling on IBM i
Groovy programming on IBM i

Debugging
How to resolve a CPI93B8 error message: LIC problem data has been logged for #MSTRTNS
Space offset X'0015FF00' or X'0000000000000000' is outside current limit for object QIGC2424C
Debugging a Web page
Top 10 programmer tips YTD
Top expert advice: 20 must-have programming tips
Evaluate the value of a function in debug
Too many handheld users crash the system
Possible to create a user-defined option to be used in the debug mode?
Debug value of pointer
How to use the ILE debugger to display the value of a variable in hexadecimal format
Debugging Research

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



iSeries Security - Security Tools, Physical Security and System Security
HomeNewsTopicsITKnowledge ExchangeTipsBlogsAsk the ExpertsMultimediaWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts