Check malloc() return value.

Fixes issue 25.
This commit is contained in:
Romain Tartière 2014-04-06 13:38:12 +02:00
parent 0ad6a09cda
commit 3085408bf2

View file

@ -188,9 +188,11 @@ freefare_get_tag_friendly_name (MifareTag tag)
char *
freefare_get_tag_uid (MifareTag tag)
{
char *res = malloc (2 * tag->info.szUidLen + 1);
char *res;
if ((res = malloc (2 * tag->info.szUidLen + 1))) {
for (size_t i =0; i < tag->info.szUidLen; i++)
snprintf (res + 2*i, 3, "%02x", tag->info.abtUid[i]);
}
return res;
}