From d02bb84b9f006ad423f9dfd32c79e06660e4a09d Mon Sep 17 00:00:00 2001 From: Tom Deakin Date: Wed, 29 Jul 2015 16:06:18 +0100 Subject: [PATCH] Check array size is not zero after resize --- common.h | 8 ++++++++ cuda-stream.cu | 1 + ocl-stream.cpp | 1 + 3 files changed, 10 insertions(+) diff --git a/common.h b/common.h index 527ca15..0c9799a 100644 --- a/common.h +++ b/common.h @@ -33,6 +33,14 @@ struct badntimes : public std::exception } }; +struct badarraysize : public std::exception +{ + virtual const char * what () const throw () + { + return "Array size must be >= 1024"; + } +}; + template < typename T > void check_solution(void* a_in, void* b_in, void* c_in) { diff --git a/cuda-stream.cu b/cuda-stream.cu index 846bba4..14e0aa2 100644 --- a/cuda-stream.cu +++ b/cuda-stream.cu @@ -81,6 +81,7 @@ int main(int argc, char *argv[]) << "Warning: array size must divide 1024" << std::endl << "Resizing array from " << OLD_ARRAY_SIZE << " to " << ARRAY_SIZE << std::endl; + if (ARRAY_SIZE == 0) throw badarraysize(); } // Get precision (used to reset later) diff --git a/ocl-stream.cpp b/ocl-stream.cpp index 76961a0..6942ac9 100644 --- a/ocl-stream.cpp +++ b/ocl-stream.cpp @@ -65,6 +65,7 @@ int main(int argc, char *argv[]) << "Warning: array size must divide 1024" << std::endl << "Resizing array from " << OLD_ARRAY_SIZE << " to " << ARRAY_SIZE << std::endl; + if (ARRAY_SIZE == 0) throw badarraysize(); } // Get precision (used to reset later)