瀏覽代碼

more use of malloc

Eric Betts 1 年之前
父節點
當前提交
b5c45a9349
共有 3 個文件被更改,包括 6 次插入30 次删除
  1. 4 28
      ccid.c
  2. 1 1
      sam_api.c
  3. 1 1
      uart.c

+ 4 - 28
ccid.c

@@ -147,11 +147,12 @@ void seader_ccid_XfrBlockToSlot(
     seader_uart->tx_len = header_len + len;
     seader_uart->tx_len = seader_add_lrc(seader_uart->tx_buf, seader_uart->tx_len);
 
-    char display[SEADER_UART_RX_BUF_SIZE * 2 + 1] = {0};
+    char* display = malloc(seader_uart->tx_len * 2 + 1);
     for(uint8_t i = 0; i < seader_uart->tx_len; i++) {
         snprintf(display + (i * 2), sizeof(display), "%02x", seader_uart->tx_buf[i]);
     }
     FURI_LOG_D(TAG, "seader_ccid_XfrBlockToSlot(%d) %d: %s", slot, seader_uart->tx_len, display);
+    free(display);
 
     furi_thread_flags_set(furi_thread_get_id(seader_uart->tx_thread), WorkerEvtSamRx);
 }
@@ -162,11 +163,12 @@ size_t seader_ccid_process(Seader* seader, uint8_t* cmd, size_t cmd_len) {
     CCID_Message message;
     message.consumed = 0;
 
-    char display[SEADER_UART_RX_BUF_SIZE * 2 + 1] = {0};
+    char* display = malloc(cmd_len * 2 + 1);
     for(uint8_t i = 0; i < cmd_len; i++) {
         snprintf(display + (i * 2), sizeof(display), "%02x", cmd[i]);
     }
     FURI_LOG_D(TAG, "seader_ccid_process %d: %s", cmd_len, display);
+    free(display);
 
     if(cmd_len == 2) {
         if(cmd[0] == CCID_MESSAGE_TYPE_RDR_to_PC_NotifySlotChange) {
@@ -253,11 +255,6 @@ size_t seader_ccid_process(Seader* seader, uint8_t* cmd, size_t cmd_len) {
         message.bError = ccid[8];
         message.payload = ccid + 10;
 
-        memset(display, 0, sizeof(display));
-        for(uint8_t i = 0; i < message.dwLength; i++) {
-            snprintf(display + (i * 2), sizeof(display), "%02x", message.payload[i]);
-        }
-
         if(cmd_len < 2 + 10 + message.dwLength + 1) {
             // Incomplete
             return message.consumed;
@@ -274,27 +271,6 @@ size_t seader_ccid_process(Seader* seader, uint8_t* cmd, size_t cmd_len) {
             return message.consumed;
         }
 
-        /*
-        if(message.dwLength == 0) {
-            FURI_LOG_D(
-                TAG,
-                "CCID [%d|%d] type: %02x, status: %02x, error: %02x",
-                message.bSlot,
-                message.bSeq,
-                message.bMessageType,
-                message.bStatus,
-                message.bError);
-        } else {
-            FURI_LOG_D(
-                TAG,
-                "CCID [%d|%d] %ld: %s",
-                message.bSlot,
-                message.bSeq,
-                message.dwLength,
-                display);
-        }
-        */
-
         //0306 81 00000000 0000 0200 01 87
         //0306 81 00000000 0000 0100 01 84
         if(message.bMessageType == CCID_MESSAGE_TYPE_RDR_to_PC_SlotStatus) {

+ 1 - 1
sam_api.c

@@ -158,7 +158,7 @@ bool seader_send_apdu(
     }
 
     uint8_t length = APDU_HEADER_LEN + payloadLen;
-    uint8_t *apdu = malloc(length);
+    uint8_t* apdu = malloc(length);
     if(!apdu) {
         FURI_LOG_E(TAG, "Failed to allocate memory for apdu in seader_send_apdu");
         return false;

+ 1 - 1
uart.c

@@ -98,7 +98,7 @@ int32_t seader_uart_worker(void* context) {
     seader_uart->tx_sem = furi_semaphore_alloc(1, 1);
 
     seader_uart->tx_thread =
-        furi_thread_alloc_ex("SeaderUartTxWorker", 3 * 1024, seader_uart_tx_thread, seader);
+        furi_thread_alloc_ex("SeaderUartTxWorker", 2 * 1024, seader_uart_tx_thread, seader);
 
     seader_uart_serial_init(seader_uart, seader_uart->cfg.uart_ch);
     seader_uart_set_baudrate(seader_uart, seader_uart->cfg.baudrate);