bounds error with lua
Posted: 28 Jul 2020, 21:58
Hi all, the problem I am reporting should be triggered by most Elmer simulations when lua functionality is parsed. I haven't provided an example because my question is about how to solve this in principal. If someone can suggested a possible solution then I am happy to implement it on my (rather large) test case. If you need me to provide a minimal example let me know and I'll try to do so.
When compiling and running Elmer (latest version, elmerice branch, but I've checked the relevant code modules in devel branch and it has the same line numbers as I give below) with bounds checking turned on I get the following error:
I believe the cause of this behaviour is that LEN(lua_result)=1, where lua_result is a fortran pointer. This comes from the call to the intrinsic function c_f_pointer at line 237 in Lua.F90. This function converts a c pointer to a fortran pointer. I don't know how to interrogate the c pointer. The fortran pointer is of type character(kind=c_char, len=:). The line that triggers the bounds error presumably works fine when bounds checking is not used (or else how would lua be parsed!), but the fact that it triggers a bounds error means that bounds checking cannot be used more generally.
A solution might be to find a way to ensure that the fortran pointer sp has a suitable LEN after this c_f_pointer call. Perhaps there are other possible solutions. I do not have any experience with Fortran/C interoperability and I don't know how to fix this. Does anyone have any ideas?
Thanks!
Rupert Gladstone
When compiling and running Elmer (latest version, elmerice branch, but I've checked the relevant code modules in devel branch and it has the same line numbers as I give below) with bounds checking turned on I get the following error:
Code: Select all
At line 1217 of file /projappl/project_2002875/source/elmer_RMG/elmerfem/fem/src/GeneralUtils.F90
Fortran runtime error: Substring out of bounds: upper bound (14) of 'lua_result' exceeds string length (1)
A solution might be to find a way to ensure that the fortran pointer sp has a suitable LEN after this c_f_pointer call. Perhaps there are other possible solutions. I do not have any experience with Fortran/C interoperability and I don't know how to fix this. Does anyone have any ideas?
Thanks!
Rupert Gladstone