]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Fix bugs catched by BEAM
authorJosef Weidendorfer <Josef.Weidendorfer@gmx.de>
Wed, 11 May 2011 12:28:01 +0000 (12:28 +0000)
committerJosef Weidendorfer <Josef.Weidendorfer@gmx.de>
Wed, 11 May 2011 12:28:01 +0000 (12:28 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11742

callgrind/dump.c
callgrind/sim.c

index edac997cab1eb2daf3ab8c268773163e320c4470..cd57f4bf77d1a8b7980cfde6873d31f36c8ab8d4 100644 (file)
@@ -336,6 +336,8 @@ static Bool print_fn_pos(int fd, FnPos* last, BBCC* bbcc)
 {
     Bool res = False;
 
+    CLG_ASSERT(bbcc && bbcc->cxt);
+
     CLG_DEBUGIF(3) {
        CLG_DEBUG(2, "+ print_fn_pos: ");
        CLG_(print_cxt)(16, bbcc->cxt, bbcc->rec_index);
@@ -351,9 +353,9 @@ static Bool print_fn_pos(int fd, FnPos* last, BBCC* bbcc)
        }
        
        if (last->cxt != bbcc->cxt) {
-           fn_node* last_from = (last->cxt && last->cxt->size>1) ?
+           fn_node* last_from = (last->cxt && last->cxt->size >1) ?
                                 last->cxt->fn[1] : 0;
-           fn_node* curr_from = (bbcc->cxt && bbcc->cxt->size>1) ?
+           fn_node* curr_from = (bbcc->cxt->size >1) ?
                                 bbcc->cxt->fn[1] : 0;
            if (curr_from == 0) {
                if (last_from != 0) {
@@ -659,13 +661,15 @@ static void fprint_jcc(Int fd, jCC* jcc, AddrPos* curr, AddrPos* last, ULong eco
       CLG_(print_jcc)(-10, jcc);
     }
 
+    CLG_ASSERT(jcc->to !=0);
+    CLG_ASSERT(jcc->from !=0);
+    
     if (!get_debug_pos(jcc->to, bb_addr(jcc->to->bb), &target)) {
        /* if we don't have debug info, don't switch to file "???" */
        target.file = last->file;
     }
 
-    if (jcc->from &&
-       (jcc->jmpkind == JmpCond || jcc->jmpkind == Ijk_Boring)) {
+    if ((jcc->jmpkind == JmpCond) || (jcc->jmpkind == Ijk_Boring)) {
            
       /* this is a JCC for a followed conditional or boring jump. */
       CLG_ASSERT(CLG_(is_zero_cost)( CLG_(sets).full, jcc->cost));
@@ -720,8 +724,6 @@ static void fprint_jcc(Int fd, jCC* jcc, AddrPos* curr, AddrPos* last, ULong eco
        return;
     }
 
-    CLG_ASSERT(jcc->to !=0);
-    
     file = jcc->to->cxt->fn[0]->file;
     obj  = jcc->to->bb->obj;
     
@@ -1635,15 +1637,19 @@ void CLG_(dump_profile)(Char* trigger, Bool only_current_thread)
      VG_(message)(Vg_DebugMsg, "Dumping done.\n");
 }
 
-/* copy command to cmd buffer (could change) */
+/* Copy command to cmd buffer. We want to original command line
+ * (can change at runtime)
+ */
 static
 void init_cmdbuf(void)
 {
   Int i,j,size = 0;
   HChar* argv;
 
-  if (VG_(args_the_exename))
+  if (VG_(args_the_exename)) {
+      CLG_ASSERT( VG_(strlen)( VG_(args_the_exename) ) < BUF_LEN-1);
       size = VG_(sprintf)(cmdbuf, " %s", VG_(args_the_exename));
+  }
 
   for(i = 0; i < VG_(sizeXA)( VG_(args_for_client) ); i++) {
       argv = * (HChar**) VG_(indexXA)( VG_(args_for_client), i );
@@ -1653,7 +1659,7 @@ void init_cmdbuf(void)
          if (size < BUF_LEN) cmdbuf[size++] = argv[j];
   }
 
-  if (size == BUF_LEN) size--;
+  if (size >= BUF_LEN) size = BUF_LEN-1;
   cmdbuf[size] = 0;
 }
 
index 2b8cbe473475e92d982f6182b4dbe68e38649f40..60b2987cccec7109125587d93e9fbb2338c8dedc 100644 (file)
@@ -977,7 +977,7 @@ void cacheuse_finish(void)
   if (!CLG_(current_state).collect) return;
 
   CLG_(bb_base) = 0;
-  current_ii = &ii;
+  current_ii = &ii; /* needs to be set for update_XX_use */
   CLG_(cost_base) = 0;
 
   /* update usage counters */
@@ -995,6 +995,8 @@ void cacheuse_finish(void)
     for (i = 0; i < LL.sets * LL.assoc; i++)
       if (LL.loaded[i].use_base)
        update_LL_use(i, 0);
+
+  current_ii = 0;
 }