ModelicaStandardLibrary icon indicating copy to clipboard operation
ModelicaStandardLibrary copied to clipboard

Over-zealous null-pointer guards in ModelicaStandardTables_CombiTimeTable_init (etc)

Open HansOlsson opened this issue 2 years ago • 4 comments

If you look at the declaration of ModelicaStandardTables_CombiTimeTable_init (and similar ones) you notice that all pointer arguments are declared to be non-NULL (using nonnull-attribute for Gcc and SAL for Visual Studio).

However, if the table is read from a file then table isn't used (or even checked) and can safely be NULL.

The correction for Gcc will be a bit messy (specify all non-NULL pointers) so I didn't want to make the PR unless it is likely to be accepted.

HansOlsson avatar Aug 31 '23 07:08 HansOlsson

Even if the table is read from file, it still gets passed as non-null double* pointer if called from a Modelica environment. Having a Modelica environment was the initial assumption though. If called from a non-Modelica environment, well, it can be different and table can be null if it should be read from file.

beutlich avatar Sep 04 '23 15:09 beutlich

Even if the table is read from file, it still gets passed as non-null double* pointer if called from a Modelica environment. Having a Modelica environment was the initial assumption though. If called from a non-Modelica environment, well, it can be different and table can be null if it should be read from file.

I assume you mean "Modelica environment" as short for "Modelica Standard Library environment", since we have some that use the C-sources directly in their Modelica code - bypassing/copying the MSL models. (In particular that's how it was found.)

HansOlsson avatar Sep 05 '23 07:09 HansOlsson

By "Modelica env" I meant a Modelica simulation environment as Dymola or SimulationX. In Modelica Language it is not possible to pass a null pointer to an external function or external object ctor.

beutlich avatar Sep 05 '23 15:09 beutlich

An idea would be to have two different ctors of the external table objects - one for construction of table from file and other for construction from passed array.

beutlich avatar Jan 13 '24 18:01 beutlich