summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2016-09-15 15:30:18 +0200
committerHaru <haru@dotalux.com>2016-10-07 01:10:28 +0200
commit872fc8d4f4a8ea60a1d97da4ca724c7b70e1af18 (patch)
treea1234320efa4f33b6c6f18f9b197be7aabdd7415 /src/common
parentc5780deadbda31d4a76e7f4ded866d769c2a1151 (diff)
downloadhercules-872fc8d4f4a8ea60a1d97da4ca724c7b70e1af18.tar.gz
hercules-872fc8d4f4a8ea60a1d97da4ca724c7b70e1af18.tar.bz2
hercules-872fc8d4f4a8ea60a1d97da4ca724c7b70e1af18.tar.xz
hercules-872fc8d4f4a8ea60a1d97da4ca724c7b70e1af18.zip
Updated VECTOR_INIT() and VECTOR_ENSURE() to be more analyzer- (and human-reader-) friendly
Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/common')
-rw-r--r--src/common/db.h17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/common/db.h b/src/common/db.h
index 1c0955221..4cbc66ade 100644
--- a/src/common/db.h
+++ b/src/common/db.h
@@ -1114,7 +1114,11 @@ HPShared struct db_interface *DB;
* @param _vec Vector.
*/
#define VECTOR_INIT(_vec) \
- memset(&(_vec), 0, sizeof(_vec))
+ do { \
+ VECTOR_DATA(_vec) = NULL; \
+ VECTOR_CAPACITY(_vec) = 0; \
+ VECTOR_LENGTH(_vec) = 0; \
+ } while(false)
/**
* Returns the internal array of values.
@@ -1220,12 +1224,11 @@ HPShared struct db_interface *DB;
*/
#define VECTOR_ENSURE(_vec, _n, _step) \
do { \
- int _empty_ = VECTOR_CAPACITY(_vec)-VECTOR_LENGTH(_vec); \
- if ((_n) > _empty_) { \
- while ((_n) > _empty_) \
- _empty_ += (_step); \
- VECTOR_RESIZE(_vec, _empty_+VECTOR_LENGTH(_vec)); \
- } \
+ int _newcapacity_ = VECTOR_CAPACITY(_vec); \
+ while ((_n) + VECTOR_LENGTH(_vec) > _newcapacity_) \
+ _newcapacity_ += (_step); \
+ if (_newcapacity_ > VECTOR_CAPACITY(_vec)) \
+ VECTOR_RESIZE(_vec, _newcapacity_); \
} while(false)
/**