]> git.xonotic.org Git - xonotic/netradiant.git/commitdiff
introduce safe_malloc0, also 0 the memory before usage
authorThomas Debesse <dev@illwieckz.net>
Tue, 14 Jan 2020 05:17:15 +0000 (06:17 +0100)
committerThomas Debesse <dev@illwieckz.net>
Mon, 20 Jan 2020 19:57:17 +0000 (20:57 +0100)
note called safe_calloc because calloc does not have the same syntax
and this safe_malloc0 uses malloc syntax

tools/quake3/common/cmdlib.c
tools/quake3/common/cmdlib.h

index 32cf7fc0f41307253fd0b1b6a84a7c67bc634126..43bf0a35e7fc3a22acc56d6f77e71a0ed12c5598 100644 (file)
@@ -69,6 +69,28 @@ void *safe_malloc_info( size_t size, char* info ){
        return p;
 }
 
+void *safe_malloc0( size_t size ){
+       void *p;
+
+       p = calloc( 1, size );
+       if ( !p ) {
+               Error( "safe_malloc0 failed on allocation of %i bytes", size );
+       }
+
+       return p;
+}
+
+void *safe_malloc0_info( size_t size, char* info ){
+       void *p;
+
+       p = calloc( 1, size );
+       if ( !p ) {
+               Error( "%s: safe_malloc0 failed on allocation of %i bytes", info, size );
+       }
+
+       return p;
+}
+
 // set these before calling CheckParm
 int myargc;
 char **myargv;
index b49e49c2e4f37e4d264af4baf16ebf099cdd173d..ecdcf6e1afd6dc42bd0375958efa36affdc5bb58 100644 (file)
@@ -66,6 +66,8 @@
 
 void *safe_malloc( size_t size );
 void *safe_malloc_info( size_t size, char* info );
+void *safe_malloc0( size_t size );
+void *safe_malloc0_info( size_t size, char* info );
 
 // set these before calling CheckParm
 extern int myargc;