From 646c2d66608e9ff8a45dc01dc307a165a3bfdd2b Mon Sep 17 00:00:00 2001 From: Matt Hill Date: Tue, 18 Feb 2014 22:19:20 -0600 Subject: [PATCH] Fixed segfault when calculating median against empty array --- src/openalpr/utility.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/openalpr/utility.cpp b/src/openalpr/utility.cpp index 4953e2c..06fd044 100644 --- a/src/openalpr/utility.cpp +++ b/src/openalpr/utility.cpp @@ -177,6 +177,12 @@ vector produceThresholds(const Mat img_gray, Config* config) double median(int array[], int arraySize) { + if (arraySize == 0) + { + //std::cerr << "Median calculation requested on empty array" << endl; + return 0; + } + std::sort(&array[0], &array[arraySize]); return arraySize % 2 ? array[arraySize / 2] : (array[arraySize / 2 - 1] + array[arraySize / 2]) / 2; }