Patchwork [1,of,5,stable,cpychecker] diffhelpers: verify hline was created before using it

login
register
mail settings
Submitter Augie Fackler
Date Jan. 27, 2015, 3:26 p.m.
Message ID <25af70176080cd54761b.1422372392@arthedain.pit.corp.google.com>
Download mbox | patch
Permalink /patch/7560/
State Accepted
Commit c8e7fa41bfc53dc23fad0e977eb56a110370fccb
Headers show

Comments

Augie Fackler - Jan. 27, 2015, 3:26 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1422371224 18000
#      Tue Jan 27 10:07:04 2015 -0500
# Branch stable
# Node ID 25af70176080cd54761b1624c900dc19252c9994
# Parent  0c4419faacbcca691737b5e25820dcbf4c7150ac
diffhelpers: verify hline was created before using it

Found with cpychecker.

Patch

diff --git a/mercurial/diffhelpers.c b/mercurial/diffhelpers.c
--- a/mercurial/diffhelpers.c
+++ b/mercurial/diffhelpers.c
@@ -34,6 +34,9 @@  static void _fix_newline(PyObject *hunk,
 		sz -= 1;
 
 	hline = PyBytes_FromStringAndSize(l, sz-1);
+	if (!hline) {
+		return NULL;
+	}
 
 	if (c == ' ' || c == '+') {
 		PyObject *rline = PyBytes_FromStringAndSize(l + 1, sz - 2);
@@ -194,4 +197,3 @@  initdiffhelpers(void)
 	                                        NULL, NULL);
 }
 #endif
-