fixed segfault when compiled with -O1 or -O2