8000 Fixed a bug that might invoke undefined behavior · learningpro/leetcode@3f189a3 · GitHub
[go: up one dir, main page]

Skip to content
{"payload":{"commit":{"oid":"3f189a32a74a2b29d1619fdafeebd7040edaf1eb","url":"/learningpro/leetcode/commit/3f189a32a74a2b29d1619fdafeebd7040edaf1eb","authoredDate":"2013-12-22T22:53:02.000+08:00","committedDate":"2013-12-22T22:53:02.000+08:00","shortMessage":null,"shortMessageMarkdown":"\u003cdiv\u003eFixed a bug that might invoke undefined behavior\u003c/div\u003e","shortMessageMarkdownLink":null,"bodyMessageHtml":"Calling front() on an empty container would invoke undefined behavior","authors":[{"login":"JasonGitHub","displayName":"JasonGitHub","avatarUrl":"https://avatars.githubusercontent.com/u/2267044?v=4","path":"/JasonGitHub","isGitHub":false}],"committerAttribution":false,"committer":{"login":"JasonGitHub","displayName":"JasonGitHub","avatarUrl":"https://avatars.githubusercontent.com/u/2267044?v=4","path":"/JasonGitHub","isGitHub":false},"parents":["4e81197cc606cd88c2918a6079eb600cdaea3ff8"],"globalRelayId":"MDY6Q29tbWl0MjM2NDc2NjI6M2YxODlhMzJhNzRhMmIyOWQxNjE5ZmRhZmVlYmQ3MDQwZWRhZjFlYg==","sha1":"4e81197cc606cd88c2918a6079eb600cdaea3ff8","sha2":"3f189a32a74a2b29d1619fdafeebd7040edaf1eb"},"currentUser":null,"repo":{"id":23647662,"defaultBranch":"master","name":"leetcode","ownerLogin":"learningpro","currentUserCanPush":false,"isFork":true,"isEmpty":false,"createdAt":"2014-09-04T03:53:53.000Z","ownerAvatar":"https://avatars.githubusercontent.com/u/1081377?v=4","public":true,"private":false,"isOrgOwned":false},"diffEntryData":[{"diffLines":[{"stylingDirective":null,"type":"HUNK","blobLineNumber":178,"text":"@@ -179,6 +179,7 @@ \\subsubsection{代码}","html":"@@ -179,6 +179,7 @@ \\subsubsection{代码}","displayNoNewLineWarning":false,"position":0,"left":178,"right":178},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":179,"text":" class Solution {","html":" class Solution {","displayNoNewLineWarning":false,"position":1,"left":179,"right":179},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":180,"text":" public:","html":" public:","displayNoNewLineWarning":false,"position":2,"left":180,"right":180},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":181,"text":" bool searchMatrix(const vector\u003cvector\u003cint\u003e\u003e\u0026 matrix, int target) {","html":" bool searchMatrix(const vector\u0026lt;vector\u0026lt;int\u0026gt;\u0026gt;\u0026amp; matrix, int target) {","displayNoNewLineWarning":false,"position":3,"left":181,"right":181},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":182,"text":"+ if (matrix.empty()) return false;","html":"+ if (matrix.empty()) return false;","displayNoNewLineWarning":false,"position":4,"left":181,"right":182},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":183,"text":" const size_t m = matrix.size();","html":" const size_t m = matrix.size();","displayNoNewLineWarning":false,"position":5,"left":182,"right":183},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":184,"text":" const size_t n = matrix.front().size();","html":" const size_t n = matrix.front().size();","displayNoNewLineWarning":false,"position":6,"left":183,"right":184},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":185,"text":" ","html":"\u003cbr\u003e","displayNoNewLineWarning":false,"position":7,"left":184,"right":185}],"diffNumber":0,"diffSize":"0 Bytes","isBinary":false,"isTooBig":false,"collapsed":false,"isSubmodule":false,"lineCount":210,"linesChanged":1,"newTreeEntry":{"lineCount":210,"path":"C++/chapSearching.tex","mode":100644,"isGenerated":false},"oldTreeEntry":{"lineCount":0,"path":"C++/chapSearching.tex","mode":100644},"linesAdded":1,"linesDeleted":0,"path":"C++/chapSearching.tex","pathDigest":"ad882ffcd8d2f69b1b86b1b712c3e157fa7b88e4eb9cbb11538b542166c9a481","status":"MODIFIED","truncatedReason":null,"oldOid":"4e81197cc606cd88c2918a6079eb600cdaea3ff8","newOid":"3f189a32a74a2b29d1619fdafeebd7040edaf1eb","copilotChatReference":null,"deletedSha":"4e81197cc606cd88c2918a6079eb600cdaea3ff8","canToggleRichDiff":false,"defaultToRichDiff":false,"proseDifffHtml":null,"renderInfo":null,"dependencyDiffPath":null,"submodule":null}],"splitViewPreference":"unified","ignoreWhitespace":false,"commentsPreference":"visible","diffLineSpacingPreference":"relaxed","useMonospaceFont":false,"pasteUrlLinkAsPlainText":false,"userNotices":[],"path":"/learningpro/leetcode/commit/3f189a32a74a2b29d1619fdafeebd7040edaf1eb","fileTreeExpanded":true,"headerInfo":{"additions":1,"deletions":0,"filesChanged":1,"filesChangedString":"1"},"moreDiffsToLoad":false,"asyncDiffLoadInfo":{"startIndex":1,"truncated":false,"byteCount":277,"lineShownCount":8},"commentInfo":{"canComment":false,"locked":false,"canLock":false,"repoArchived":false},"csrf_tokens":{"/users/diffview?diff=split":{"post":"3Qoj4TZlkNRcQlEkpDniPda2IriahzUhQG1yKqX6FOUvJ7x6hhg42rrGtsuxWtnzLOyHUjPcIonc-TOAyrSCiQ"},"/users/diffview?diff=unified":{"post":"10-lujO4ljy7QyKPxx72jVNjwV9a0pJ4hu9U51imlHwlYjohg8U-Ml3HxWDSfc1DqTlktfOJhdAaexVNN-gCEA"},"/notifications/thread":{"post":"v0gf-vXQ4Z6uQhCS-lgxjiblXznXiCuHAOaEZDEVE-Iyubf6efGGune0aOSffCg4KhmBxHe3QXhD2cTc6xlEVw"}}},"title":"Fixed a bug that might invoke undefined behavior · learningpro/leetcode@3f189a3","appPayload":{"helpUrl":"https://docs.github.com","findInDiffWorkerPath":"/assets-cdn/worker/find-in-diff-worker-f6b2312e7da9.js","enabled_features":{"diff_ux_refresh_beta":false,"diff_inline_comments":false,"diff_ux_refresh_ssr_five":false,"diff_ux_refresh_ssr_ten":false}}}

Commit 3f189a3

Browse files
committed
Fixed a bug that might invoke undefined behavior
Calling front() on an empty container would invoke undefined behavior
1 parent 4e81197 commit 3f189a3

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

C++/chapSearching.tex

+1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ \subsubsection{代码}
179179
class Solution {
180180
public:
181181
bool searchMatrix(const vector<vector<int>>& matrix, int target) {
182+
if (matrix.empty()) return false;
182183
const size_t m = matrix.size();
183184
const size_t n = matrix.front().size();
184185

0 commit comments

Comments
 (0)
0