bdiff: fix malloc(0) issue in fixws() stable
authorJim Hague <jim.hague@acm.org>
Fri, 03 Feb 2012 23:27:17 +0000
branchstable
changeset 16071 8134ec8627e7
parent 16070 f11eee00c652
child 16086 d1538789a1b3
bdiff: fix malloc(0) issue in fixws() If fixws() is called on a zero-length string, malloc(0) is called and expected to return a pointer. Which it does on e.g. Linux. AIX returns NULL, which it is also legal, but the malloc() is then assumed to have failed. So ensure a valid pointer is always returned.
mercurial/bdiff.c
--- a/mercurial/bdiff.c	Mon Feb 06 14:37:49 2012 +0900
+++ b/mercurial/bdiff.c	Fri Feb 03 23:27:17 2012 +0000
@@ -443,7 +443,7 @@
 	r = PyBytes_AsString(s);
 	rlen = PyBytes_Size(s);
 
-	w = (char *)malloc(rlen);
+	w = (char *)malloc(rlen ? rlen : 1);
 	if (!w)
 		goto nomem;