From: Junhwan Park Date: Fri, 18 Aug 2017 07:09:39 +0000 (+0900) Subject: apps/examples: fix svace warning X-Git-Tag: 1.1_Public_Release~166^2~17 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=28815c9687e9fec529e9837c26f9687583f48857;p=rtos%2Ftinyara.git apps/examples: fix svace warning I changed some warnings found in the svace test. - I added a return check to some functions. - Changed unnecessary variable settings. Change-Id: Iaf4c2785dafe085e9a887ed0e8dc969bd398e244 Signed-off-by: Junhwan Park Conflicts: apps/examples/security_api/security_api_tc_main.c --- diff --git a/apps/examples/sensorbd_demo/examples/gpio_buttons.c b/apps/examples/sensorbd_demo/examples/gpio_buttons.c index 5a7660d..bfd5f1a 100644 --- a/apps/examples/sensorbd_demo/examples/gpio_buttons.c +++ b/apps/examples/sensorbd_demo/examples/gpio_buttons.c @@ -92,8 +92,14 @@ void switch_main(int argc, char *argv[]) for (j = 0; j < nbtns; j++) { if (poll_list[j].revents & POLLIN) { char buf[4]; - lseek(poll_list[j].fd, 0, SEEK_SET); - read(poll_list[j].fd, buf, sizeof(buf)); + if (lseek(poll_list[j].fd, 0, SEEK_SET) < 0) { + printf("lseek error\n"); + return; + } + if (read(poll_list[j].fd, buf, sizeof(buf)) < 0) { + printf("read error\n"); + return; + } printf("%s is %s\n", buttons[j].name, buf[0] == '1' ? "rising" : "falling"); diff --git a/apps/examples/sensorbd_demo/examples/gpio_ledonoff.c b/apps/examples/sensorbd_demo/examples/gpio_ledonoff.c index cc2ebc7..bc26ebd 100644 --- a/apps/examples/sensorbd_demo/examples/gpio_ledonoff.c +++ b/apps/examples/sensorbd_demo/examples/gpio_ledonoff.c @@ -59,9 +59,16 @@ static void gpio_write(int port, int value) static char devpath[16]; snprintf(devpath, 16, "/dev/gpio%d", port); int fd = open(devpath, O_RDWR); + if (fd < 0) { + printf("fd open fail\n"); + return; + } ioctl(fd, GPIOIOC_SET_DIRECTION, GPIO_DIRECTION_OUT); - write(fd, str, snprintf(str, 4, "%d", value != 0) + 1); + if (write(fd, str, snprintf(str, 4, "%d", value != 0) + 1) < 0) { + printf("write error\n"); + return; + } close(fd); } diff --git a/apps/examples/sensorbd_demo/examples/gpio_loopback.c b/apps/examples/sensorbd_demo/examples/gpio_loopback.c index b999abf..7803d3d 100644 --- a/apps/examples/sensorbd_demo/examples/gpio_loopback.c +++ b/apps/examples/sensorbd_demo/examples/gpio_loopback.c @@ -67,8 +67,15 @@ static int gpio_read(int port) char devpath[16]; snprintf(devpath, 16, "/dev/gpio%d", port); int fd = open(devpath, O_RDWR); + if (fd < 0) { + printf("fd open fail\n"); + return -1; + } - read(fd, buf, sizeof(buf)); + if (read(fd, buf, sizeof(buf)) < 0) { + printf("read error\n"); + return -1; + } close(fd); return buf[0] == '1'; @@ -80,9 +87,16 @@ static void gpio_write(int port, int value) char devpath[16]; snprintf(devpath, 16, "/dev/gpio%d", port); int fd = open(devpath, O_RDWR); + if (fd < 0) { + printf("fd open fail\n"); + return; + } ioctl(fd, GPIOIOC_SET_DIRECTION, GPIO_DIRECTION_OUT); - write(fd, buf, snprintf(buf, sizeof(buf), "%d", !!value)); + if (write(fd, buf, snprintf(buf, sizeof(buf), "%d", !!value)) < 0) { + printf("write error\n"); + return; + } close(fd); } @@ -104,8 +118,6 @@ void gpioloopback_main(int argc, char *argv[]) nA = XGPIO1; nB = XGPIO3; break; - default: - break; } int readA, readB; diff --git a/apps/examples/sensorbd_demo/examples/gpio_starterled.c b/apps/examples/sensorbd_demo/examples/gpio_starterled.c index a731b88..ebee574 100644 --- a/apps/examples/sensorbd_demo/examples/gpio_starterled.c +++ b/apps/examples/sensorbd_demo/examples/gpio_starterled.c @@ -61,7 +61,10 @@ static int gpio_read(int port) int fd = open(devpath, O_RDWR); ioctl(fd, GPIOIOC_SET_DIRECTION, GPIO_DIRECTION_IN); - read(fd, buf, sizeof(buf)); + if (read(fd, buf, sizeof(buf)) < 0) { + printf("read error\n"); + return -1; + } close(fd); return buf[0] == '1'; @@ -75,7 +78,10 @@ static void gpio_write(int port, int value) int fd = open(devpath, O_RDWR); ioctl(fd, GPIOIOC_SET_DIRECTION, GPIO_DIRECTION_OUT); - write(fd, buf, snprintf(buf, sizeof(buf), "%d", !!value)); + if (write(fd, buf, snprintf(buf, sizeof(buf), "%d", !!value)) < 0) { + printf("write error\n"); + return; + } close(fd); } diff --git a/apps/examples/sensorbd_demo/examples/i2c_mpu9250.c b/apps/examples/sensorbd_demo/examples/i2c_mpu9250.c index d1b8d5e..72771a8 100644 --- a/apps/examples/sensorbd_demo/examples/i2c_mpu9250.c +++ b/apps/examples/sensorbd_demo/examples/i2c_mpu9250.c @@ -180,22 +180,10 @@ int mpu9250_main(int argc, char *argv[]) for (i = 0; i < 30; i++) { data[0] = mpu9250_get_axis(MPU9250_AXIS_X); - if (data[0] < 0) { - break; - } - data[1] = mpu9250_get_axis(MPU9250_AXIS_Y); - if (data[1] < 0) { - break; - } - data[2] = mpu9250_get_axis(MPU9250_AXIS_Z); - if (data[2] < 0) { - break; - } printf("ACC: %-10d%-10d%-10d\n", (int16_t)data[0], (int16_t)data[1], (int16_t)data[2]); - up_mdelay(500); } diff --git a/apps/examples/sensorbd_demo/examples/i2c_tcs34725.c b/apps/examples/sensorbd_demo/examples/i2c_tcs34725.c index 7d5f6d8..0aaa2e0 100644 --- a/apps/examples/sensorbd_demo/examples/i2c_tcs34725.c +++ b/apps/examples/sensorbd_demo/examples/i2c_tcs34725.c @@ -173,7 +173,7 @@ static uint16_t tcs34725_calctemperature(uint16_t r, uint16_t g, uint16_t b) static void tcs34725_initialize(void) { - uint8_t reg; + uint8_t reg = 0; tcs34725IntegrationTime = TCS34725_INTEGRATIONTIME_50MS; tcs34725_read(TCS34725_ID, ®, 1); @@ -209,6 +209,7 @@ void tcs34725_main(int argc, char *argv[]) tcs34725_initialize(); + r = g = b = c = temp = lux = 0; for (i = 0; i < 30; i++) { tcs34725_getdata(&r, &g, &b, &c); diff --git a/apps/examples/sensorbd_demo/examples/pwm_buzzer.c b/apps/examples/sensorbd_demo/examples/pwm_buzzer.c index 242318d..85c1459 100644 --- a/apps/examples/sensorbd_demo/examples/pwm_buzzer.c +++ b/apps/examples/sensorbd_demo/examples/pwm_buzzer.c @@ -80,6 +80,10 @@ void pwmbuzzer_main(int argc, char *argv[]) /* device 0 channel 1 */ fd = open("/dev/pwm1", O_RDWR); + if (fd < 0) { + printf("fd open fail\n"); + return; + } for (i = 0; i < 8; i++) { pwm_info.frequency = octavef1[i]; @@ -97,6 +101,10 @@ void pwmbuzzer_main(int argc, char *argv[]) /* device 0 channel 2 */ fd = open("/dev/pwm2", O_RDWR); + if (fd < 0) { + printf("fd open fail\n"); + return; + } for (i = 0; i < 8; i++) { pwm_info.frequency = octavef2[i]; diff --git a/apps/examples/sensorbd_demo/examples/pwm_led.c b/apps/examples/sensorbd_demo/examples/pwm_led.c index 7ac4151..c5baaae 100644 --- a/apps/examples/sensorbd_demo/examples/pwm_led.c +++ b/apps/examples/sensorbd_demo/examples/pwm_led.c @@ -63,9 +63,25 @@ void ledpwm_main(int argc, char *argv[]) struct pwm_info_s pwm_info; fd1 = open("/dev/pwm0", O_RDWR); + if (fd1 < 0) { + printf("fd open fail\n"); + return; + } fd2 = open("/dev/pwm3", O_RDWR); + if (fd2 < 0) { + printf("fd open fail\n"); + return; + } fd3 = open("/dev/pwm4", O_RDWR); + if (fd3 < 0) { + printf("fd open fail\n"); + return; + } fd4 = open("/dev/pwm5", O_RDWR); + if (fd4 < 0) { + printf("fd open fail\n"); + return; + } pwm_info.frequency = 1000; for (i = 0; i < 100; i = i + 3) {