Good call, thank you.
System Development Manager, Service Delivery Platform
From: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Barbara Morris
Sent: Friday, November 17, 2017 5:48 PM
Subject: Re: RPG & Teraspace Storage Model
On 2017-11-16 2:14 PM, Kurt Anderson wrote:
Barbara, one thing I changed from your sample code is making this based on the 'cur' pointer. I just wanted to make sure I was right in doing that (and it wasn't a fluke that it was working for me).
dcl-s gSoapMsg_view char(MAX_ELEM_LEN)
based(gp_soapMsg_cur); // can't be
Kurt, that was a bug in my code. You're right, it has to be based on the 'cur' pointer.
There's another nasty bug in my code. "Nasty", because it might not actually cause a problem until long after it was deployed.
Here's my code for reallocating the pointer. See the line marked BUG.
// Make sure there's room
gSoapMsgNewLen = gSoapMsgLen + %len(value);
if gSoapMsgNewLen > gSoapMsgAllocSize;
// Allocate more storage
BUG gSoapMsgAllocSize += SOAP_INCREMENT;
gp_SoapMsg = %Realloc(gp_SoapMsg : gSoapMsgAllocSize);
// Reposition any pointers within gp_SoapMsg
gp_soapMsg_cur = gp_SoapMsg + gSoapMsgLen;
It's not sufficient to just add the SOAP_INCREMENT size. The string being added might be longer than that, and appending the new string could cause some other allocation in the heap to get corrupted.
It should be
gSoapMsgAllocSize += %len(value) + SOAP_INCREMENT;
To add enough room for the current string plus some extra room to prevent too many reallocations.
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at https://archive.midrange.com/rpg400-l
Please contact support@xxxxxxxxxxxx for any subscription related questions.
Help support midrange.com by shopping at amazon.com with our affiliate link: http://amzn.to/2dEadiD