* renamed malloc.h mymalloc.h, and added MALLARG as the type of the

argument to malloc() (size_t or unsigned int)

* listobject.c: check for overflow of the size of the object,
  so things like range(0x7fffffff) will raise MemoryError instead
  of calling malloc() with -4 (and then crashing -- malloc's fault)
This commit is contained in:
Guido van Rossum 1992-08-19 16:46:30 +00:00
parent b001f7adb1
commit 1e28e5e596
4 changed files with 83 additions and 3 deletions

View file

@ -34,10 +34,16 @@ newlistobject(size)
{
int i;
listobject *op;
MALLARG nbytes;
if (size < 0) {
err_badcall();
return NULL;
}
nbytes = size * sizeof(object *);
/* Check for overflow */
if (nbytes / sizeof(object *) != size) {
return err_nomem();
}
op = (listobject *) malloc(sizeof(listobject));
if (op == NULL) {
return err_nomem();
@ -46,7 +52,7 @@ newlistobject(size)
op->ob_item = NULL;
}
else {
op->ob_item = (object **) malloc(size * sizeof(object *));
op->ob_item = (object **) malloc(nbytes);
if (op->ob_item == NULL) {
free((ANY *)op);
return err_nomem();