From 7553af8acf8b5d008dabf9cc4375ea89ee503a88 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Thu, 23 Sep 2004 23:59:17 +0000 Subject: [PATCH] Minor allocation hook corrections. --- archivers/zip.c | 9 +++++++-- physfs.h | 4 +++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/archivers/zip.c b/archivers/zip.c index ee3792e4..872a6d62 100644 --- a/archivers/zip.c +++ b/archivers/zip.c @@ -192,8 +192,13 @@ static voidpf zlibPhysfsAlloc(voidpf opaque, uInt items, uInt size) PHYSFS_allocator *allocator = __PHYSFS_getAllocator(); size_t total = (items * size) + sizeof (PHYSFS_memhandle); PHYSFS_memhandle h = allocator->malloc(total); - char *ptr = (char *) allocator->lock(h); - PHYSFS_memhandle *ph = (PHYSFS_memhandle *) ptr; + char *ptr; + PHYSFS_memhandle *ph; + if (h == NULL) + return(NULL); + + ptr = (char *) allocator->lock(h); + ph = (PHYSFS_memhandle *) ptr; *ph = h; /* tuck the memhandle in front of the memory block... */ return(ptr + sizeof (PHYSFS_memhandle)); } /* zlibPhysfsAlloc */ diff --git a/physfs.h b/physfs.h index 5b13ece8..c8a57571 100644 --- a/physfs.h +++ b/physfs.h @@ -1834,7 +1834,9 @@ __EXPORT__ int PHYSFS_writeUBE64(PHYSFS_file *file, PHYSFS_uint64 val); * because it's convenient for systems to have handles be the same size * as a pointer, but they shouldn't be assumed to point to valid memory * (or to memory at all). The allocator in use will convert from memhandles - * to valid pointers to allocated memory. + * to valid pointers to allocated memory. A memhandle of NULL is considered + * to be bogus (so malloc can return a NULL handle), even though it's not + * technically a NULL pointer in itself. * * \sa PHYSFS_allocator * \sa PHYSFS_setAllocator