svn rev #23448: trunk/src/include/

ghudson@MIT.EDU ghudson at MIT.EDU
Sat Dec 5 17:53:04 EST 2009


http://src.mit.edu/fisheye/changelog/krb5/?cs=23448
Commit By: ghudson
Log Message:
Make the alloc_data and k5alloc convenience functions work if the
caller requests zero bytes, by allocating one byte instead.



Changed Files:
U   trunk/src/include/k5-int.h
Modified: trunk/src/include/k5-int.h
===================================================================
--- trunk/src/include/k5-int.h	2009-12-05 13:47:37 UTC (rev 23447)
+++ trunk/src/include/k5-int.h	2009-12-05 22:53:04 UTC (rev 23448)
@@ -2811,7 +2811,8 @@
 static inline krb5_error_code
 alloc_data(krb5_data *data, unsigned int len)
 {
-    char *ptr = (char *) calloc(len, 1);
+    /* Allocate at least one byte since zero-byte allocs may return NULL. */
+    char *ptr = (char *) calloc((len > 0) ? len : 1, 1);
 
     if (ptr == NULL)
         return ENOMEM;
@@ -2837,11 +2838,12 @@
 
 /* Allocate zeroed memory; set *code to 0 on success or ENOMEM on failure. */
 static inline void *
-k5alloc(size_t size, krb5_error_code *code)
+k5alloc(size_t len, krb5_error_code *code)
 {
     void *ptr;
 
-    ptr = calloc(size, 1);
+    /* Allocate at least one byte since zero-byte allocs may return NULL. */
+    ptr = calloc((len > 0) ? len : 1, 1);
     *code = (ptr == NULL) ? ENOMEM : 0;
     return ptr;
 }




More information about the cvs-krb5 mailing list