[GiNaC-list] bug in ex::ex(const std::string&, const ex&)

Diego Conti diego.conti at unipi.it
Wed Apr 3 10:23:45 CEST 2024


Hi,

I think there is a bug in the functions that convert strings to ex. I 
attach a minimal program that segfaults on my machine.

I am using gcc 13.2.0 on Ubuntu 23.10, x86_64, CPU Intel i9-12900H.

The problem only arises if I compile GiNaC using the CMake script. The 
same program works if I compile with configure && make.

The problem appears to be in parser/default_reader.cpp, where 
conversions between pointers to functions and integers are used. The 
code assumes that the integer underlylng a pointer to function is even, 
relying on the fact that functions are aligned; this latter condition 
appears to fail on my system when compiling with CMake.

Indeed, inserting a pragma command  inside parser/default_reader.cpp 
(see attached patch) fixes the problem. I do not know if this can be 
made portable across compilers; maybe it would be easier to modify the 
code by replacing reader_func with a class that handles the conversion 
in a type-safe way?

Diego Conti

-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.diff
Type: text/x-patch
Size: 58 bytes
Desc: not available
URL: <http://www.ginac.de/pipermail/ginac-list/attachments/20240403/1ab62140/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sqrtbug.cpp
Type: text/x-c++src
Size: 147 bytes
Desc: not available
URL: <http://www.ginac.de/pipermail/ginac-list/attachments/20240403/1ab62140/attachment-0001.bin>


More information about the GiNaC-list mailing list