logo

gcc编译添加-ftrapv后(整数溢出检查)发现一个ut core了,部分堆栈如下:

#0  0x00002aaaae86fb55 in raise () from /lib64/libc.so.6
#1  0x00002aaaae871131 in abort () from /lib64/libc.so.6
#2  0x00002aaaae62a326 in __addvdi3 () from /lib64/libgcc_s.so.1
#3  0x0000000000641186 in std::chrono::operator+<long, std::ratio<1l, 1000000000l>, long, std::ratio<1l, 1000000000l> > (__lhs=..., __rhs=...)
    at /usr/local/gcc-4.7.2/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/chrono:363
#4  0x000000000064120f in std::chrono::operator+<LogCabin::Core::Time::CSteadyClock, std::chrono::duration<long, std::ratio<1l, 1000000000l> >, long, std::ratio<1l, 1000000000l> > (__lhs=..., __rhs=...)
    at /usr/local/gcc-4.7.2/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/chrono:596
#5  0x00002aaaaddda4f5 in LogCabin::Server::StateMachine::setInhibit (this=0x2aaab40177b0, duration=...)
    at /home/ccj/GMDB-BUILD/dmdb/src/logcabin/Server/StateMachine.cc:287
#6  0x00000000007ade7f in LogCabin::Server::(anonymous namespace)::ServerStateMachineTest_setInhibit_Test::TestBody (
    this=0x2aaab4016300) at /home/ccj/xxx/test/ut/logcabin/Server/StateMachineTest.cc:379

使用了-ftrapv选项后,加法运算不使用cpu指令,而是直接调用GCC附属库libgcc.c中的函数addvdi3,在addvdi3函数中,
加法运算的结果会与加数进行比较,如果结果小于加数,则调用abort函数,程序报错。
看代码
StateMachineTest.cc:379

stateMachine->setInhibit(std::chrono::nanoseconds::max());

可以这里传入的数据太大,造成溢出,在__addvdi3函数中abort掉了。
StateMachine.cc:287
https://github.com/logcabin/logcabin/blob/master/Server/StateMachine.cc#L287

maySnapshotAt = now + duration;

看代码后面,发现有溢出的处理。


ccj 于 2016-07-13 19:41 修改
0 回复
需要 登录 后方可回复, 如果你还没有账号你可以 注册 一个帐号。