Coverity: fix issues in aml-utils [1/1]
PD#SWPL-172616
Problem:
Some coverity issues has been found
1.uninit
2.invalid type
3.use after free
Solution:
1.Initialize variables before use
2.format with the correct format specifier
3.avoid double free
Verify:
coverity scan
Signed-off-by: kirk.wang <kirk.wang@amlogic.com>
Change-Id: Ibb959cd98165d085d56100b9ae8006e504436349
diff --git a/utils/simulate_key.c b/utils/simulate_key.c
index 1106587..8bd3691 100644
--- a/utils/simulate_key.c
+++ b/utils/simulate_key.c
@@ -40,7 +40,7 @@
int main(int argc, char *argv[]) {
unsigned int keycode;
int fd_kbd;
- char eventname[32];
+ char eventname[32] = {0};
FILE *fp;
const char *deviceInfo = "/proc/bus/input/devices";
diff --git a/utils/usb_monitor.c b/utils/usb_monitor.c
index f934b4a..6429b6c 100644
--- a/utils/usb_monitor.c
+++ b/utils/usb_monitor.c
@@ -121,7 +121,7 @@
if (strcmp(argv[1], "-h")) {
if (strlen(argv[1]) > (MAX_CUSTOMIZED_PATH_LENGTH -1)) {
ret = -1;
- printf("udc file path length %d exceeds max file path length %d\n", strlen(argv[1]), MAX_CUSTOMIZED_PATH_LENGTH-1);
+ printf("udc file path length %zu exceeds max file path length %d\n", strlen(argv[1]), MAX_CUSTOMIZED_PATH_LENGTH-1);
} else {
strncpy(CUSTOMIZED_UDC_FILE_PATH, argv[1], sizeof(CUSTOMIZED_UDC_FILE_PATH));
CUSTOMIZED_UDC_FILE_PATH[MAX_CUSTOMIZED_PATH_LENGTH - 1] = '\0';
diff --git a/utils/wifi_power.c b/utils/wifi_power.c
index da6e443..20c9633 100644
--- a/utils/wifi_power.c
+++ b/utils/wifi_power.c
@@ -30,7 +30,6 @@
if (ioctl(fd, SDIO_POWER_DOWN) < 0) {
if (ioctl(fd, USB_POWER_DOWN) < 0) {
fprintf(stderr, "Set Wi-Fi power down error!!!\n");
- close(fd);
ret = false;
}
}
@@ -39,7 +38,6 @@
if (ioctl(fd, SDIO_POWER_UP) < 0) {
if (ioctl(fd, USB_POWER_UP) < 0) {
fprintf(stderr, "Set Wi-Fi power up error!!!\n");
- close(fd);
ret = false;
}
}
@@ -47,7 +45,6 @@
case 2: {
if (ioctl(fd, SDIO_GET_DEV_TYPE, dev_type) < 0) {
fprintf(stderr, "Failed to get dev type!!!\n");
- close(fd);
ret = false;
} else
fprintf(stdout, "inf=%s\n", dev_type);