From caa44fe6ed9d848a52f712fbe900ad3e932d7da4 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Thu, 25 Nov 2010 10:04:27 -0500 Subject: [PATCH] tracefile.c: Seek fix Made the tracefile.c seek more robust. Fixes a rare crash where high can be lower than low in a seek. Matthew Khouzam : I am including an example to better illustrace my fix. the current binary search has a case where high can be lower then low. An example: 51 blocks, the element is somewhere in the 12th block. trace of before : low : 0, high 51 , block_num -1 low : 0, high 24 , block_num 25 low : 13, high 24 , block_num 12 low : 13, high 17 , block_num 18 low : 13, high 14 , block_num 15 low : 13, high 12 , block_num 13 This will assert and fail. The trace after will produce the following walkthrough low : 0, high 51 , block_num -1 low : 0, high 24 , block_num 25 low : 0, high 24 , block_num 12 Found! Reported-by: Matthew Khouzam Signed-off-by: Mathieu Desnoyers --- ltt/tracefile.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ltt/tracefile.c b/ltt/tracefile.c index 0d8a248e..012ce108 100644 --- a/ltt/tracefile.c +++ b/ltt/tracefile.c @@ -1094,8 +1094,11 @@ int ltt_tracefile_seek_time(LttTracefile *tf, LttTime time) } } else if(ltt_time_compare(time, tf->buffer.begin.timestamp) < 0) { - /* go to lower part */ - high = block_num - 1; + /* + * Go to lower part. We don't want block_num - 1 since block_num + * can equal low , in which case high < low. + */ + high = block_num; } else if(ltt_time_compare(time, tf->buffer.end.timestamp) > 0) { /* go to higher part */ low = block_num + 1; -- 2.34.1