From: Julian Seward Date: Sat, 6 Aug 2016 07:15:30 +0000 (+0000) Subject: Fix invalid code caught by Ubsan, in which we compute the address X-Git-Tag: svn/VALGRIND_3_12_0~93 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c6e56acc75db17a38a587cfe7ae3efddfba625ee;p=thirdparty%2Fvalgrind.git Fix invalid code caught by Ubsan, in which we compute the address of "cgs->events[-1]", even though it isn't dereferenced. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15930 --- diff --git a/cachegrind/cg_main.c b/cachegrind/cg_main.c index de0c2a98a7..8a21bf2f8d 100644 --- a/cachegrind/cg_main.c +++ b/cachegrind/cg_main.c @@ -914,7 +914,6 @@ void addEvent_Dr ( CgState* cgs, InstrInfo* inode, Int datasize, IRAtom* ea ) static void addEvent_Dw ( CgState* cgs, InstrInfo* inode, Int datasize, IRAtom* ea ) { - Event* lastEvt; Event* evt; tl_assert(isIRAtom(ea)); @@ -924,15 +923,16 @@ void addEvent_Dw ( CgState* cgs, InstrInfo* inode, Int datasize, IRAtom* ea ) return; /* Is it possible to merge this write with the preceding read? */ - lastEvt = &cgs->events[cgs->events_used-1]; - if (cgs->events_used > 0 - && lastEvt->tag == Ev_Dr - && lastEvt->Ev.Dr.szB == datasize - && lastEvt->inode == inode - && eqIRAtom(lastEvt->Ev.Dr.ea, ea)) - { - lastEvt->tag = Ev_Dm; - return; + if (cgs->events_used > 0) { + Event* lastEvt = &cgs->events[cgs->events_used-1]; + if ( lastEvt->tag == Ev_Dr + && lastEvt->Ev.Dr.szB == datasize + && lastEvt->inode == inode + && eqIRAtom(lastEvt->Ev.Dr.ea, ea)) + { + lastEvt->tag = Ev_Dm; + return; + } } /* No. Add as normal. */ diff --git a/callgrind/main.c b/callgrind/main.c index b62e835da3..69b0ddba29 100644 --- a/callgrind/main.c +++ b/callgrind/main.c @@ -637,7 +637,6 @@ void addEvent_Dr ( ClgState* clgs, InstrInfo* inode, Int datasize, IRAtom* ea ) static void addEvent_Dw ( ClgState* clgs, InstrInfo* inode, Int datasize, IRAtom* ea ) { - Event* lastEvt; Event* evt; tl_assert(isIRAtom(ea)); tl_assert(datasize >= 1); @@ -645,15 +644,16 @@ void addEvent_Dw ( ClgState* clgs, InstrInfo* inode, Int datasize, IRAtom* ea ) tl_assert(datasize <= CLG_(min_line_size)); /* Is it possible to merge this write with the preceding read? */ - lastEvt = &clgs->events[clgs->events_used-1]; - if (clgs->events_used > 0 - && lastEvt->tag == Ev_Dr - && lastEvt->Ev.Dr.szB == datasize - && lastEvt->inode == inode - && eqIRAtom(lastEvt->Ev.Dr.ea, ea)) - { - lastEvt->tag = Ev_Dm; - return; + if (clgs->events_used > 0) { + Event* lastEvt = &clgs->events[clgs->events_used-1]; + if ( lastEvt->tag == Ev_Dr + && lastEvt->Ev.Dr.szB == datasize + && lastEvt->inode == inode + && eqIRAtom(lastEvt->Ev.Dr.ea, ea)) + { + lastEvt->tag = Ev_Dm; + return; + } } /* No. Add as normal. */