From c6e56acc75db17a38a587cfe7ae3efddfba625ee Mon Sep 17 00:00:00 2001 From: Julian Seward Date: Sat, 6 Aug 2016 07:15:30 +0000 Subject: [PATCH] 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 --- cachegrind/cg_main.c | 20 ++++++++++---------- callgrind/main.c | 20 ++++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) 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. */ -- 2.47.2