diff options
author | Adam Borowski <kilobyte@angband.pl> | 2011-02-10 01:16:24 +0100 |
---|---|---|
committer | Adam Borowski <kilobyte@angband.pl> | 2011-02-11 03:28:20 +0100 |
commit | 699dfacca9355c85a12a34f3946d17e96517451d (patch) | |
tree | 966f35c9b36947409ae7fc977af5b3f0ba5b6b30 /crawl-ref/source/fixedvector.h | |
parent | 199e032f32f978cef4b96fff4b8d8730847082ef (diff) | |
download | crawl-ref-699dfacca9355c85a12a34f3946d17e96517451d.tar.gz crawl-ref-699dfacca9355c85a12a34f3946d17e96517451d.zip |
A better assert message for FixedVector our of bounds access.
Diffstat (limited to 'crawl-ref/source/fixedvector.h')
-rw-r--r-- | crawl-ref/source/fixedvector.h | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/crawl-ref/source/fixedvector.h b/crawl-ref/source/fixedvector.h index 3afacd0898..bc72ed25a3 100644 --- a/crawl-ref/source/fixedvector.h +++ b/crawl-ref/source/fixedvector.h @@ -61,13 +61,29 @@ public: size_t size() const { return SIZE; } // ----- Access ----- - TYPE& operator[](unsigned long index) { - ASSERT(index < SIZE); + TYPE& operator[](unsigned long index) + { +#ifdef ASSERTS + if (index >= SIZE) + { + // Intentionally printed as signed, it's very, very unlikely we'd + // have a genuine big number here, but underflows are common. + die("FixedVector out of bounds (%ld / %ld)", (signed long)index, + SIZE); + } +#endif return mData[index]; } - const TYPE& operator[](unsigned long index) const { - ASSERT(index < SIZE); + const TYPE& operator[](unsigned long index) const + { +#ifdef ASSERTS + if (index >= SIZE) + { + die("FixedVector out of bounds (%ld / %ld)", (signed long)index, + SIZE); + } +#endif return mData[index]; } |