[Python-checkins] r71227 - python/branches/py3k-short-float-repr/Python/dtoa.c

mark.dickinson python-checkins at python.org
Sun Apr 5 14:28:49 CEST 2009


Author: mark.dickinson
Date: Sun Apr  5 14:28:48 2009
New Revision: 71227

Log:
Add return value checking to multadd, s2b, i2b, mult


Modified:
   python/branches/py3k-short-float-repr/Python/dtoa.c

Modified: python/branches/py3k-short-float-repr/Python/dtoa.c
==============================================================================
--- python/branches/py3k-short-float-repr/Python/dtoa.c	(original)
+++ python/branches/py3k-short-float-repr/Python/dtoa.c	Sun Apr  5 14:28:48 2009
@@ -391,7 +391,7 @@
 #ifdef Omit_Private_Memory
 		rv = (Bigint *)MALLOC(sizeof(Bigint) + (x-1)*sizeof(ULong));
 		if (rv == NULL)
-			goto error;
+			return NULL;
 #else
 		len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1)
 			/sizeof(double);
@@ -402,14 +402,13 @@
 		else {
 			rv = (Bigint*)MALLOC(len*sizeof(double));
 			if (rv == NULL)
-				goto error;
+				return NULL;
 			}
 #endif
 		rv->k = k;
 		rv->maxwds = x;
 		}
 	rv->sign = rv->wds = 0;
-  error:
 	return rv;
 	}
 
@@ -465,6 +464,10 @@
 	if (carry) {
 		if (wds >= b->maxwds) {
 			b1 = Balloc(b->k+1);
+			if (b1 == NULL){
+				Bfree(b);
+				return NULL;
+			}
 			Bcopy(b1, b);
 			Bfree(b);
 			b = b1;
@@ -486,20 +489,28 @@
 	x = (nd + 8) / 9;
 	for(k = 0, y = 1; x > y; y <<= 1, k++) ;
 	b = Balloc(k);
+	if (b == NULL)
+		return NULL;
 	b->x[0] = y9;
 	b->wds = 1;
 
 	i = 9;
 	if (9 < nd0) {
 		s += 9;
-		do b = multadd(b, 10, *s++ - '0');
-			while(++i < nd0);
+		do {
+			b = multadd(b, 10, *s++ - '0');
+			if (b == NULL)
+				return NULL;
+		} while(++i < nd0);
 		s += dplen;
 		}
 	else
 		s += dplen + 9;
-	for(; i < nd; i++)
+	for(; i < nd; i++) {
 		b = multadd(b, 10, *s++ - '0');
+		if (b == NULL)
+			return NULL;
+		}
 	return b;
 	}
 
@@ -584,6 +595,8 @@
 	Bigint *b;
 
 	b = Balloc(1);
+	if (b == NULL)
+		return NULL;
 	b->x[0] = i;
 	b->wds = 1;
 	return b;
@@ -616,6 +629,8 @@
 	if (wc > a->maxwds)
 		k++;
 	c = Balloc(k);
+	if (c == NULL)
+		return NULL;
 	for(x = c->x, xa = x + wc; x < xa; x++)
 		*x = 0;
 	xa = a->x;


More information about the Python-checkins mailing list