]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Fix invalid code caught by Ubsan, in which we compute the address
authorJulian Seward <jseward@acm.org>
Sat, 6 Aug 2016 07:15:30 +0000 (07:15 +0000)
committerJulian Seward <jseward@acm.org>
Sat, 6 Aug 2016 07:15:30 +0000 (07:15 +0000)
of "cgs->events[-1]", even though it isn't dereferenced.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15930

cachegrind/cg_main.c
callgrind/main.c

index de0c2a98a7f740d6e6d8c03d48ab437175685071..8a21bf2f8d5232ad3effd393282542eedefc08a1 100644 (file)
@@ -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. */
index b62e835da3d81f3e6bcc2b54eebe5020c5600fe3..69b0ddba2951e9d2c685f49b29ff4aa58d4733a3 100644 (file)
@@ -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. */