fix missing tests on malloc() return
This commit is contained in:
parent
06d5b54308
commit
69c435f348
3 changed files with 17 additions and 0 deletions
|
@ -130,6 +130,10 @@ uart_flush_input(serial_port sp)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
char *rx = malloc(available_bytes_count);
|
char *rx = malloc(available_bytes_count);
|
||||||
|
if (!rx) {
|
||||||
|
perror("malloc");
|
||||||
|
return;
|
||||||
|
}
|
||||||
// There is something available, read the data
|
// There is something available, read the data
|
||||||
(void)read(UART_DATA(sp)->fd, rx, available_bytes_count);
|
(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);
|
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)
|
uart_list_ports(void)
|
||||||
{
|
{
|
||||||
char **res = malloc(sizeof(char *));
|
char **res = malloc(sizeof(char *));
|
||||||
|
if (!res) {
|
||||||
|
perror("malloc");
|
||||||
|
return res;
|
||||||
|
}
|
||||||
size_t szRes = 1;
|
size_t szRes = 1;
|
||||||
|
|
||||||
res[0] = NULL;
|
res[0] = NULL;
|
||||||
|
|
|
@ -250,11 +250,19 @@ char **
|
||||||
uart_list_ports(void)
|
uart_list_ports(void)
|
||||||
{
|
{
|
||||||
char **availablePorts = malloc((1 + MAX_SERIAL_PORT_WIN) * sizeof(char *));
|
char **availablePorts = malloc((1 + MAX_SERIAL_PORT_WIN) * sizeof(char *));
|
||||||
|
if (!availablePorts) {
|
||||||
|
perror("malloc");
|
||||||
|
return availablePorts;
|
||||||
|
}
|
||||||
int curIndex = 0;
|
int curIndex = 0;
|
||||||
int i;
|
int i;
|
||||||
for (i = 1; i <= MAX_SERIAL_PORT_WIN; i++) {
|
for (i = 1; i <= MAX_SERIAL_PORT_WIN; i++) {
|
||||||
if (is_port_available(i)) {
|
if (is_port_available(i)) {
|
||||||
availablePorts[curIndex] = (char *)malloc(10);
|
availablePorts[curIndex] = (char *)malloc(10);
|
||||||
|
if (!availablePorts[curIndex]) {
|
||||||
|
perror("malloc");
|
||||||
|
break;
|
||||||
|
}
|
||||||
sprintf(availablePorts[curIndex], "COM%d", i);
|
sprintf(availablePorts[curIndex], "COM%d", i);
|
||||||
// printf("found candidate port: %s\n", availablePorts[curIndex]);
|
// printf("found candidate port: %s\n", availablePorts[curIndex]);
|
||||||
curIndex++;
|
curIndex++;
|
||||||
|
|
|
@ -3097,6 +3097,7 @@ pn53x_current_target_new(const struct nfc_device *pnd, const nfc_target *pnt)
|
||||||
free(CHIP_DATA(pnd)->current_target);
|
free(CHIP_DATA(pnd)->current_target);
|
||||||
}
|
}
|
||||||
CHIP_DATA(pnd)->current_target = malloc(sizeof(nfc_target));
|
CHIP_DATA(pnd)->current_target = malloc(sizeof(nfc_target));
|
||||||
|
// TODO: test malloc
|
||||||
memcpy(CHIP_DATA(pnd)->current_target, pnt, sizeof(nfc_target));
|
memcpy(CHIP_DATA(pnd)->current_target, pnt, sizeof(nfc_target));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue