diff --git a/libnfc/buses/uart_posix.c b/libnfc/buses/uart_posix.c index 8fbe743..9525e70 100644 --- a/libnfc/buses/uart_posix.c +++ b/libnfc/buses/uart_posix.c @@ -130,6 +130,10 @@ uart_flush_input(serial_port sp) return; } char *rx = malloc(available_bytes_count); + if (!rx) { + perror("malloc"); + return; + } // There is something available, read the data (void)read(UART_DATA(sp)->fd, rx, available_bytes_count); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%d bytes have eatten.", available_bytes_count); @@ -338,6 +342,10 @@ char ** uart_list_ports(void) { char **res = malloc(sizeof(char *)); + if (!res) { + perror("malloc"); + return res; + } size_t szRes = 1; res[0] = NULL; diff --git a/libnfc/buses/uart_win32.c b/libnfc/buses/uart_win32.c index 941bde0..2360dc1 100644 --- a/libnfc/buses/uart_win32.c +++ b/libnfc/buses/uart_win32.c @@ -250,11 +250,19 @@ char ** uart_list_ports(void) { char **availablePorts = malloc((1 + MAX_SERIAL_PORT_WIN) * sizeof(char *)); + if (!availablePorts) { + perror("malloc"); + return availablePorts; + } int curIndex = 0; int i; for (i = 1; i <= MAX_SERIAL_PORT_WIN; i++) { if (is_port_available(i)) { availablePorts[curIndex] = (char *)malloc(10); + if (!availablePorts[curIndex]) { + perror("malloc"); + break; + } sprintf(availablePorts[curIndex], "COM%d", i); // printf("found candidate port: %s\n", availablePorts[curIndex]); curIndex++; diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index e10ca91..5957165 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -3097,6 +3097,7 @@ pn53x_current_target_new(const struct nfc_device *pnd, const nfc_target *pnt) free(CHIP_DATA(pnd)->current_target); } CHIP_DATA(pnd)->current_target = malloc(sizeof(nfc_target)); + // TODO: test malloc memcpy(CHIP_DATA(pnd)->current_target, pnt, sizeof(nfc_target)); }