[27845] in CVS-changelog-for-Kerberos-V5

home help back first fref pref prev next nref lref last post

krb5 commit: Add k5calloc internal helper function

daemon@ATHENA.MIT.EDU (Greg Hudson)
Mon Jul 15 00:45:49 2013

Date: Mon, 15 Jul 2013 00:43:06 -0400
From: Greg Hudson <ghudson@mit.edu>
Message-Id: <201307150443.r6F4h6i4001433@drugstore.mit.edu>
To: cvs-krb5@mit.edu
Reply-To: krbdev@mit.edu
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: cvs-krb5-bounces@mit.edu

https://github.com/krb5/krb5/commit/90f9f6f6708baff4de2162c5eb754bb4bc557845
commit 90f9f6f6708baff4de2162c5eb754bb4bc557845
Author: Greg Hudson <ghudson@mit.edu>
Date:   Thu Jul 11 19:47:33 2013 -0400

    Add k5calloc internal helper function
    
    Letting calloc() do multiplication helps avoid overflow bugs, so
    provide an internal k5calloc() helper which accepts both calloc
    arguments, and reimplement k5alloc() in terms of it.

 src/include/k5-int.h |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/include/k5-int.h b/src/include/k5-int.h
index 63e0e8a..e820b1c 100644
--- a/src/include/k5-int.h
+++ b/src/include/k5-int.h
@@ -2182,16 +2182,23 @@ authdata_eq(krb5_authdata a1, krb5_authdata a2)
 
 /* Allocate zeroed memory; set *code to 0 on success or ENOMEM on failure. */
 static inline void *
-k5alloc(size_t len, krb5_error_code *code)
+k5calloc(size_t nmemb, size_t size, krb5_error_code *code)
 {
     void *ptr;
 
     /* Allocate at least one byte since zero-byte allocs may return NULL. */
-    ptr = calloc((len > 0) ? len : 1, 1);
+    ptr = calloc(nmemb ? nmemb : 1, size ? size : 1);
     *code = (ptr == NULL) ? ENOMEM : 0;
     return ptr;
 }
 
+/* Allocate zeroed memory; set *code to 0 on success or ENOMEM on failure. */
+static inline void *
+k5alloc(size_t size, krb5_error_code *code)
+{
+    return k5calloc(1, size, code);
+}
+
 /* Return a copy of the len bytes of memory at in; set *code to 0 or ENOMEM. */
 static inline void *
 k5memdup(const void *in, size_t len, krb5_error_code *code)
_______________________________________________
cvs-krb5 mailing list
cvs-krb5@mit.edu
https://mailman.mit.edu/mailman/listinfo/cvs-krb5

home help back first fref pref prev next nref lref last post