From 5036155913ebcd2c5d1b3de1ae175cf398b0b319 Mon Sep 17 00:00:00 2001 From: Joe Caswell Date: Wed, 27 Feb 2013 16:19:04 -0500 Subject: [PATCH] verify seq_int resume value is not out of bounds --- src/basho_bench_keygen.erl | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/basho_bench_keygen.erl b/src/basho_bench_keygen.erl index 60e85ad52..69fc02aa8 100644 --- a/src/basho_bench_keygen.erl +++ b/src/basho_bench_keygen.erl @@ -122,7 +122,7 @@ sequential_int_generator(Ref, MaxValue, Id, DisableProgress) -> %% dictionary to keep track of where we are. case erlang:get({sigen, Ref}) of undefined -> - seq_gen_put(Ref, seq_gen_read_resume_value(Id)), + seq_gen_put(Ref, seq_gen_read_resume_value(Id, MaxValue)), sequential_int_generator(Ref, MaxValue, Id, DisableProgress); MaxValue -> throw({stop, empty_keygen}); @@ -158,7 +158,7 @@ seq_gen_write_resume_value(Id, Value) -> ok = file:rename(OutFileTmp, OutFile) end. -seq_gen_read_resume_value(Id) -> +seq_gen_read_resume_value(Id, MaxValue) -> case seq_gen_state_dir(Id) of "" -> 0; @@ -167,8 +167,14 @@ seq_gen_read_resume_value(Id) -> InFile = Path ++ "/" ++ integer_to_list(Id), {ok, Bin} = file:read_file(InFile), Value = binary_to_term(Bin), - ?DEBUG("Id ~p resuming from value ~p\n", [Id, Value]), - Value + case Value > MaxValue of + true -> + ?WARN("Id ~p resume value ~p exceeds maximum value ~p. Restarting from 0",[Id, Value, MaxValue]), + 0; + false -> + ?DEBUG("Id ~p resuming from value ~p\n", [Id, Value]), + Value + end catch error:{badmatch, _} -> 0;