summaryrefslogtreecommitdiffstats
path: root/sigcore/Hat.h
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2009-04-16 21:46:34 -0400
committerBen Boeckel <MathStuf@gmail.com>2009-04-16 21:46:34 -0400
commit8dc999cbb19133edf64999457e3e671750555c7d (patch)
treeb2cf2dce2aca02d19055e462a2d6554c96604f88 /sigcore/Hat.h
parentdae87264fe1e43bd101f2c004083a7e98a0b0bff (diff)
downloadsigen-8dc999cbb19133edf64999457e3e671750555c7d.tar.gz
sigen-8dc999cbb19133edf64999457e3e671750555c7d.tar.xz
sigen-8dc999cbb19133edf64999457e3e671750555c7d.zip
Can't pick or take from an empty hat
Diffstat (limited to 'sigcore/Hat.h')
-rw-r--r--sigcore/Hat.h6
1 files changed, 5 insertions, 1 deletions
diff --git a/sigcore/Hat.h b/sigcore/Hat.h
index c4e2c7c2..87ea6b3d 100644
--- a/sigcore/Hat.h
+++ b/sigcore/Hat.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com>
+ * Copyright 2007-2009 Ben Boeckel <MathStuf@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -110,6 +110,8 @@ template<class T> inline Hat<T>::Hat() :
template<class T> inline T Hat<T>::pick() const
{
+ if (!m_count)
+ return T();
int choice = qrand() % m_count;
QList<T> keys = m_items.keys();
foreach (const T& key, keys)
@@ -123,6 +125,8 @@ template<class T> inline T Hat<T>::pick() const
template<class T> inline T Hat<T>::take()
{
+ if (!m_count)
+ return T();
T chosen = pick();
if (!(--m_items[chosen]))
m_items.remove(chosen);