Apply suggestions from @henrygab

Check if memory allocation fails
Fix memory leak
Initialize struct in declaration
Add/Fix some notes
Remove unlikely() in favor of readability
Remove a hard-coded magic number
This commit is contained in:
wh201906 committed 2023-11-15 18:04:52 +08:00
1 parent 835b7a9150
commit 3ee13c9ba6
12 files changed
+113 -44

No files matched your search

+5
View File
@@ -118,6 +118,10 @@ int demodHID(bool verbose) {
uint32_t hi2 = 0, hi = 0, lo = 0;
uint8_t *bits = malloc(g_GraphTraceLen);
if (bits == NULL) {
PrintAndLogEx(FAILED, "failed to allocate memory");
return PM3_EMALLOC;
}
size_t size = getFromGraphBuf(bits);
if (size == 0) {
PrintAndLogEx(DEBUG, "DEBUG: Error - " _RED_("HID not enough samples"));
@@ -142,6 +146,7 @@ int demodHID(bool verbose) {
else
PrintAndLogEx(DEBUG, "DEBUG: Error - " _RED_("HID error demoding fsk %d"), idx);
free(bits);
return PM3_ESOFT;
}