Atozed Forums

Full Version: Array memory bounds issue
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi there.  I had an interesting situation in IntraWeb 15.0.17 in a 64bit Delphi 10.2.3 stand alone application.  I have the following array declarations in the user session unit.

    bTabOpenBottom : array [0..1] of boolean;
    bTabOpenTop : array [0..4] of boolean;

I had a bug in my program where I was attempting to read UserSession.bTabOpenBottom[2] from another form and the system merrily accepted the command and instead accessed the first element of the next array.  At least that is what the IW system looked like it did.  Took me a while to figure out why I was getting such odd results and when I changed the array declarations around and then my program behaviour would change.  Rather interesting when I figured out that the system allowed access to unknown memory outside of the array bounds.

The system should have actually have thrown an exception since bTabOpenBottom only has up to 1.  I just wanted to report this since I am used to applications crashing when this occurs or throwing some sort of exception.  This could lead to a IW crash on the server since who knows what memory is being accessed and windows may not like it.  Better to catch in testing with an exception or crash.

Cheers!
Hi Bob,

IW is not responsible for memory access in this case. There is nothing we can do to avoid that, because it doesn't rely on IW library code to do such access.

Delphi compiler generates the code to access indexed properties like that. I think you can turn on Range Checking in your Delphi compiler options. AFAIK it will catch such errors. Range Checking is - by default - disabled in all Delphi applications.
Hi Alexandre. Amazing that such a critical feature is defaulted off. I wonder when this was changed in Delphi since I cannot remember this being an issue in older versions. Rather standard compilation to protect memory. Thank you so much fore pointing this out and I have updated this setting in my environment. Cheers!