Closed svigerske closed 3 years ago
Hi Stefan,
I cannot reproduce this. Could you provide the example, platform, compiler? You are on the master branch?
Gleb
Save
#include "mp/nl-reader.h"
int main()
{
mp::NullNLHandler<void*> handler;
mp::ReadNLFile("alan.nl", handler);
return EXIT_SUCCESS;
}
as pr134.cpp into the main source dir, put https://www.minlplib.org/nl/alan.nl next to it, and run
g++ pr134.cpp -Iinclude src/format.cc src/expr-info.cc src/nl-reader.cc src/os.cc src/posix.cc -fsanitize=undefined -g && ./a.out
With GCC 10 on ArchLinux, I get
include/mp/nl-reader.h:1246:25: runtime error: load of misaligned address 0x7fad530e81e2 for type 'const int', which requires 4 byte alignment
0x7fad530e81e2: note: pointer points here
6f 31 0a 43 00 00 00 00 73 00 00 43 01 00 00 00 73 00 00 43 02 00 00 00 73 00 00 43 03 00 00 00
^
include/mp/nl-reader.h:1246:25: runtime error: load of misaligned address 0x7fad530e81e7 for type 'const short int', which requires 2 byte alignment
0x7fad530e81e7: note: pointer points here
00 00 00 73 00 00 43 01 00 00 00 73 00 00 43 02 00 00 00 73 00 00 43 03 00 00 00 73 00 00 43 04
^
include/mp/nl-reader.h:1258:25: runtime error: load of misaligned address 0x7fad530e82c4 for type 'const double', which requires 8 byte alignment
0x7fad530e82c4: note: pointer points here
00 00 00 00 56 76 62 27 76 62 d3 3f 01 00 00 00 d5 61 27 76 62 27 b6 3f 02 00 00 00 7c 62 27 76
^
I'm on master (the last release is already 5 years old).
Problem is that integers may not be stored at an address that is a multiple of SizeOf(Int)
, so converting the char*
to an int*
gives this error. Same for other types larger than 1 byte.
Yep I needed -fsanitize=undefined, then it works on other examples too.
I guess it should return this->Convert(value). Please add that, or I'll change the code myself.
I got this warning from a sanitizer when reading a .nl file with ReadNLFile:
This pull request fixes this by copying the bytes to an aligned memory instead of casting.