revlog: handle errors from index_node() in nt_insert() and index_slice_del()
authorMartin von Zweigbergk <martinvonz@google.com>
Fri, 11 May 2018 23:28:02 -0700
changeset 37999 514605777244
parent 37998 5fa4e29ba3e3
child 38001 d9185fa1e868
revlog: handle errors from index_node() in nt_insert() and index_slice_del() Same idea as in a9d9802d577e (revlog: don't say "not found" on internal error, 2018-05-04). Differential Revision: https://phab.mercurial-scm.org/D3558
mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c	Mon May 14 13:11:04 2018 +0200
+++ b/mercurial/cext/revlog.c	Fri May 11 23:28:02 2018 -0700
@@ -1068,10 +1068,12 @@
 			return 0;
 		}
 		if (v < 0) {
-			const char *oldnode = index_node(self, -(v + 1));
+			const char *oldnode = index_node_existing(self, -(v + 1));
 			int noff;
 
-			if (!oldnode || !memcmp(oldnode, node, 20)) {
+			if (oldnode == NULL)
+				return -1;
+			if (!memcmp(oldnode, node, 20)) {
 				n->children[k] = -rev - 1;
 				return 0;
 			}
@@ -1850,10 +1852,11 @@
 			Py_ssize_t i;
 
 			for (i = start + 1; i < self->length - 1; i++) {
-				const char *node = index_node(self, i);
+				const char *node = index_node_existing(self, i);
+				if (node == NULL)
+					return -1;
 
-				if (node)
-					nt_insert(self, node, -1);
+				nt_insert(self, node, -1);
 			}
 			if (self->added)
 				nt_invalidate_added(self, 0);