Guard against empty list

Rotating an empty list gives badarith so add a guard clause, since the
result of rotating an empty list is well known.

BugzID: 17801


Project: http://git-wip-us.apache.org/repos/asf/couchdb-mem3/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-mem3/commit/beb54c9f
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-mem3/tree/beb54c9f
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-mem3/diff/beb54c9f

Branch: refs/heads/import
Commit: beb54c9fdf5e301c9c2bfb95ca3b1dfcf7d6397a
Parents: cfbb280
Author: Robert Newson <robert.new...@cloudant.com>
Authored: Thu Mar 7 15:29:35 2013 -0600
Committer: Robert Newson <robert.new...@cloudant.com>
Committed: Thu Mar 7 15:37:55 2013 -0600

----------------------------------------------------------------------
 src/mem3.erl | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-mem3/blob/beb54c9f/src/mem3.erl
----------------------------------------------------------------------
diff --git a/src/mem3.erl b/src/mem3.erl
index 18257ba..10dfac0 100644
--- a/src/mem3.erl
+++ b/src/mem3.erl
@@ -222,6 +222,8 @@ choose_ushards(DbName, Shards) ->
     {_, Result} = lists:foldl(Fun, {0, []}, Groups),
     Result.
 
+rotate_list(_DbName, []) ->
+    [];
 rotate_list(DbName, List) ->
     {H, T} = lists:split(erlang:crc32(DbName) rem length(List), List),
     T ++ H.

Reply via email to