Patchwork D5258: manifest: perform cheap checks before potentially allocating memory

login
register
mail settings
Submitter phabricator
Date Nov. 13, 2018, 11:42 a.m.
Message ID <0124b6835d8f68b8eee49fc5992701bb@localhost.localdomain>
Download mbox | patch
Permalink /patch/36537/
State Not Applicable
Headers show

Comments

phabricator - Nov. 13, 2018, 11:42 a.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGda4478ca0e32: manifest: perform cheap checks before potentially allocating memory (authored by durin42, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D5258?vs=12507&id=12512

REVISION DETAIL
  https://phab.mercurial-scm.org/D5258

AFFECTED FILES
  mercurial/cext/manifest.c

CHANGE DETAILS




To: durin42, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/cext/manifest.c b/mercurial/cext/manifest.c
--- a/mercurial/cext/manifest.c
+++ b/mercurial/cext/manifest.c
@@ -137,13 +137,13 @@ 
 			return MANIFEST_TOO_SHORT_LINE;
 		}
 		next++; /* advance past newline */
-		if (!realloc_if_full(self)) {
-			return MANIFEST_OOM; /* no memory */
-		}
 		if (prev && strcmp(prev, data) > -1) {
 			/* This data isn't sorted, so we have to abort. */
 			return MANIFEST_NOT_SORTED;
 		}
+		if (!realloc_if_full(self)) {
+			return MANIFEST_OOM; /* no memory */
+		}
 		l = self->lines + ((self->numlines)++);
 		l->start = data;
 		l->len = next - data;