Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Memory Access Violation

gelarimer
Beginner
626 Views

I have been troubleshooting a memory access
violation and found the following line of code
in a function that initializes the OPENFILENAME
structure:

OFN%LpStrFileTitle = LOC(gszFileTitle//"*.txt"C)

Where gszFileTitle is a Global variable.

code should have been:

OFN%LpStrFileTitle = NULL

LOC(gszFileTitle//"*.txt"C) does not produce a
compiler error, so I assume that a temporary memory
location is created to hold the string
gszFileTitle//"*.txt"//ACHAR(0). However, after the
function returns I assume the address becomes invalid.

If the paragraph above is correct it would explain
the memory access violation.

Any comments would be appreciated.

0 Kudos
2 Replies
Steven_L_Intel1
Employee
626 Views
Your understanding is correct. You are allowed to take LOC(expression), but the expression is on the routine local stack and the address is no longer valid after the routine exits.
0 Kudos
gelarimer
Beginner
626 Views
Thanks Steve. The program ran for a couple of years before the memory access violations started to occur.Apparently a minor change in another routinecausedthe fn. GetOpenFileName(OFN) to overwrite a critical memory location. That location was the invalid address retained by OFN%LpStrFileTitle. The OFN structure is alsoGlobal.
0 Kudos
Reply