Avoid causing an assertion failure in VG_(make_ExeContext_from_StackTrace)
in the case where VG_(clo_backtrace_size) < N_FRAMES (that is, with
--num-callers=N where N < N_FRAMES).


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@8820 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/helgrind/libhb_core.c b/helgrind/libhb_core.c
index dc1cee5..103b7c2 100644
--- a/helgrind/libhb_core.c
+++ b/helgrind/libhb_core.c
@@ -2955,6 +2955,10 @@
    return (void*)( ((UWord)p) & ((UWord)w) );
 }
 
+inline static UInt min_UInt ( UInt a, UInt b ) {
+   return a < b ? a : b;
+}
+
 /* Compare the intervals [a1,a1+n1) and [a2,a2+n2).  Return -1 if the
    first interval is lower, 1 if the first interval is higher, and 0
    if there is any overlap.  Redundant paranoia with casting is there
@@ -3177,7 +3181,8 @@
          tl_assert(cand_rcec->magic == RCEC_MAGIC);
          tl_assert(cand_szB >= 1);
          *resEC  = VG_(make_ExeContext_from_StackTrace)(
-                      &cand_rcec->frames[1], N_FRAMES
+                      &cand_rcec->frames[1],
+                      min_UInt(N_FRAMES, VG_(clo_backtrace_size))
                    );
          *resThr = cand_thr;
          *resSzB = cand_szB;