summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2008-05-13 18:39:15 +0000
committersmatz <smatz@openttd.org>2008-05-13 18:39:15 +0000
commit3670a25e3af5e64e430878b8ccafb2a38e0e0e70 (patch)
treeefebb74d60b6be868ca9624b19c97f1c122f93f4
parent6ae37e6339a31789729aac493d1d17753a59b93b (diff)
downloadopenttd-3670a25e3af5e64e430878b8ccafb2a38e0e0e70.tar.xz
(svn r13072) -Fix (r12995): possible out-of-bounds access
-rw-r--r--src/engine.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/engine.cpp b/src/engine.cpp
index ac50f811b..715fdebf8 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -120,7 +120,11 @@ Engine::~Engine()
*/
void EngList_Sort(EngineList *el, EngList_SortTypeFunction compare)
{
- qsort(&((*el)[0]), el->size(), sizeof(EngineID), compare);
+ size_t size = el->size();
+ /* out-of-bounds access at the next line for size == 0 (even with operator[] at some systems)
+ * generally, do not sort if there are less than 2 items */
+ if (size < 2) return;
+ qsort(&(el->at(0)), size, sizeof(EngineID), compare);
}
/** Sort selected range of items (on indices @ <begin, begin+num_items-1>)