calloc and check. remove add char.

This commit is contained in:
iceman1001 2021-10-10 14:26:00 +02:00
commit 1ab9d24b5c
2 changed files with 9 additions and 4 deletions

View file

@ -20,7 +20,7 @@ def print_atr(df):
if (len(a) == 0 or len(b) == 0): if (len(a) == 0 or len(b) == 0):
continue continue
b = b.replace('\\', '\\\\') b = b.replace('\\', '\\\\').replace('', '')
print(f' {{ "{a}", "{b}" }},') print(f' {{ "{a}", "{b}" }},')

View file

@ -20,22 +20,27 @@ const char *getAtrInfo(const char *atr_str) {
int match = -1; int match = -1;
// skip last element of AtrTable // skip last element of AtrTable
for (int i = 0; i < ARRAYLEN(AtrTable) - 1; ++i) { for (int i = 0; i < ARRAYLEN(AtrTable) - 1; ++i) {
if (strlen(AtrTable[i].bytes) != slen) if (strlen(AtrTable[i].bytes) != slen)
continue; continue;
if (strstr(AtrTable[i].bytes, "..") != NULL) { if (strstr(AtrTable[i].bytes, "..") != NULL) {
char *tmp_atr = malloc(slen); char *tmp_atr = calloc(slen, sizeof(uint8_t));
if (!tmp_atr) { if (tmp_atr == NULL) {
PrintAndLogEx(ERR, "Out of memory error in getAtrInfo(). Aborting..."); PrintAndLogEx(FAILED, "failed to allocate memory");
return NULL; return NULL;
} }
for (int j = 0; j < slen; j++) { for (int j = 0; j < slen; j++) {
tmp_atr[j] = AtrTable[i].bytes[j]=='.' ? '.' : atr_str[j]; tmp_atr[j] = AtrTable[i].bytes[j]=='.' ? '.' : atr_str[j];
} }
if (strncmp(tmp_atr, AtrTable[i].bytes, slen) == 0) { if (strncmp(tmp_atr, AtrTable[i].bytes, slen) == 0) {
// record partial match but continue looking for full match // record partial match but continue looking for full match
match = i; match = i;
} }
free(tmp_atr); free(tmp_atr);
} else { } else {
if (strncmp(atr_str, AtrTable[i].bytes, slen) == 0) return AtrTable[i].desc; if (strncmp(atr_str, AtrTable[i].bytes, slen) == 0) return AtrTable[i].desc;
} }