From 3f189a32a74a2b29d1619fdafeebd7040edaf1eb Mon Sep 17 00:00:00 2001 From: JasonGitHub Date: Sun, 22 Dec 2013 22:53:02 +0800 Subject: [PATCH] Fixed a bug that might invoke undefined behavior Calling front() on an empty container would invoke undefined behavior --- C++/chapSearching.tex | 1 + 1 file changed, 1 insertion(+) diff --git a/C++/chapSearching.tex b/C++/chapSearching.tex index d668f0c1..e008d75b 100644 --- a/C++/chapSearching.tex +++ b/C++/chapSearching.tex @@ -179,6 +179,7 @@ \subsubsection{代码} class Solution { public: bool searchMatrix(const vector>& matrix, int target) { + if (matrix.empty()) return false; const size_t m = matrix.size(); const size_t n = matrix.front().size();