aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGreg Hudson <ghudson@mit.edu>2009-12-05 22:53:04 +0000
committerGreg Hudson <ghudson@mit.edu>2009-12-05 22:53:04 +0000
commitba7405e522ad803525a28f473c4e1b16df94d3e9 (patch)
tree964297cb7cb0377934a909ab6bfc25407263afac /src
parente97a6305417bfb1949b50f243aff3a918b054245 (diff)
downloadkrb5-ba7405e522ad803525a28f473c4e1b16df94d3e9.zip
krb5-ba7405e522ad803525a28f473c4e1b16df94d3e9.tar.gz
krb5-ba7405e522ad803525a28f473c4e1b16df94d3e9.tar.bz2
Make the alloc_data and k5alloc convenience functions work if the
caller requests zero bytes, by allocating one byte instead. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@23448 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src')
-rw-r--r--src/include/k5-int.h8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/include/k5-int.h b/src/include/k5-int.h
index cbe0fd9..04e3310 100644
--- a/src/include/k5-int.h
+++ b/src/include/k5-int.h
@@ -2811,7 +2811,8 @@ string2data(char *str)
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 @@ 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 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;
}