Previous Thread
Next Thread
Print Thread
Potential array member passing issue #37374 05 Jun 24 08:00 PM
Joined: Nov 2006
Posts: 2,223
S
Stephen Funkhouser Offline OP
Member
OP Offline
Member
S
Joined: Nov 2006
Posts: 2,223
We have some generated XTREE cell validation/onchange function calls to code in our custom written .bsi modules. They pass the array element as a parameter that can be updated by the callee function with xputarg

.gen generated code is calling like this
Code
PRIVATE DIMX dlg'enter'backstock_xtr'backstock_ans(1),x,223,AUTO_EXTEND            ! answer array

	rc = fn'dlg'enter'backstock_xtr'backstock_col_description_onChanged(ansrec=dlg'enter'backstock_xtr'backstock_ans(cell.row), row=cell.row, exitcode=exitcode)


.bsi - custom written validation logic (not exact but close enough to represent the issue)
Code
FUNCTION fn'dlg'enter'backstock_xtr'backstock_col_description_onChanged(ansrec as DLG'ENTER'BACKSTOCK_XTR'BACKSTOCK_ANSARY'STRUCT, row as f8, exitcode as f8) as f8
    IF (not'valid) 
        .fn = NotValid
        Set focus on the cell
    ELSE
       if valid 
           populate ansrec read only columns data (.i.e item stock number, quantity info etc)
           add a blank row the xtree
    ENDIF
  $exit:
	XPUTARG @ansrec
ENDFUNCTION


The issue we have seen is with one row in the XTREE array, when validation passes and we add a row to the array before the xputarg occurs, the first row of data is blank. This is not XTREE issue, but what we think is happening, the AUTO_EXTEND array is being moved in memory and caller code is still pointing to the original memory location. Thus, the first row of data is lost to wherever in memory the previous location of the array was.

Hopefully, this is clear enough. Is this a valid issue?



Stephen Funkhouser
Diversified Data Solutions
Re: Potential array member passing issue [Re: Stephen Funkhouser] #37375 05 Jun 24 08:31 PM
Joined: Jun 2001
Posts: 11,794
J
Jack McGregor Offline
Member
Offline
Member
J
Joined: Jun 2001
Posts: 11,794
Seems plausible, although I'm not sure I see the full picture. What I think I see is:
  • The dlg'enter'backstock_str'backstock'ans() array is private to the bsi but therefore shared globally by all the routines in the bsi.
  • The user does something with the tree to trigger an exit for validation, which calls this _onChanged() routine, passing it a copy of the existing row.
  • The _onChanged() routine then adds an element to the array (presumably referencing the private/shared copy directly, or perhaps calls another function within the same .bsi to do that).


At that point, the address of the array element passed to the _onChanged() function may become invalid (if adding a row to the array caused it to be relocated). So yes, the XPUTARG subsequent to the auto-extension of the array would not only fail to update the correct location but it would corrupt some other location.

The solution to that would be to do the XPUTARG first before extending the array. Or, just let the _onChanged() routine operate on the array directly rather than just seeing the one element.
Other than that, I'm not sure there's any simple way for ASB to detect the problem, since when you pass an array element, the called routine doesn't have any good way to trace it back to the array base descriptor.

Re: Potential array member passing issue [Re: Stephen Funkhouser] #37378 06 Jun 24 09:25 PM
Joined: Nov 2006
Posts: 2,223
S
Stephen Funkhouser Offline OP
Member
OP Offline
Member
S
Joined: Nov 2006
Posts: 2,223
I think you see the full picture. I thought it was a bigger concern that might need to be addressed. I can see that it's not easy to address.

We have modified our problematic code.


Stephen Funkhouser
Diversified Data Solutions

Moderated by  Jack McGregor, Ty Griffin 

Powered by UBB.threads™ PHP Forum Software 7.7.3