From 0ad6a09cdabb935e4a47333d754133b4b53a7907 Mon Sep 17 00:00:00 2001 From: Robert Clausecker Date: Wed, 19 Mar 2014 18:20:38 +0100 Subject: [PATCH] Tell apart malloc failure from no application in mifare_application_write() --- libfreefare/mifare_application.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libfreefare/mifare_application.c b/libfreefare/mifare_application.c index b18d4b8..f41c726 100644 --- a/libfreefare/mifare_application.c +++ b/libfreefare/mifare_application.c @@ -265,8 +265,11 @@ mifare_application_write (MifareTag tag, Mad mad, const MadAid aid, const void * MifareClassicSectorNumber *sectors = mifare_application_find (mad, aid); MifareClassicSectorNumber *s = sectors; - if (!sectors) - return errno = EBADF, -1; + if (!sectors) { + /* mifare_application_find may also fail if malloc() fails */ + if (errno != ENOMEM) errno = EBADF; + return -1; + } while (*s && nbytes && (res >= 0)) { MifareClassicBlockNumber first_block = mifare_classic_sector_first_block (*s);