From: Theodore Tso Date: Fri, 26 Feb 1993 21:01:19 +0000 (+0000) Subject: Work around code where malloc(0) returns 0 X-Git-Tag: krb5-1.0-beta3~319 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=53999e11de5fb7d7f6e4a768dab00a04d6a4aa79;p=krb5.git Work around code where malloc(0) returns 0 git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@2510 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/krb/copy_data.c b/src/lib/krb5/krb/copy_data.c index 31f10ea81..652944a19 100644 --- a/src/lib/krb5/krb/copy_data.c +++ b/src/lib/krb5/krb/copy_data.c @@ -43,15 +43,23 @@ krb5_data **outdata; { krb5_data *tempdata; + if (!indata) { + *outdata = 0; + return 0; + } + if (!(tempdata = (krb5_data *)malloc(sizeof(*tempdata)))) return ENOMEM; - *tempdata = *indata; - if (!(tempdata->data = malloc(tempdata->length))) { - xfree(tempdata); - return ENOMEM; - } - memcpy((char *)tempdata->data, (char *)indata->data, tempdata->length); + tmpdata->length = indata->length; + if (tempdata->length) { + if (!(tempdata->data = malloc(tempdata->length))) { + xfree(tempdata); + return ENOMEM; + } + memcpy((char *)tempdata->data, (char *)indata->data, tempdata->length); + } else + tempdata->data = 0; *outdata = tempdata; return 0; }