hqd: Fix Klocwork errors in liblight

1. Fix null pointer de-reference klocwork error in liblight.
2. sprintf is part of ScanBan function. Replace sprintf with
   snprintf.

Change-Id: I0b88967a2bdf4adf563753c09df88d2c6a432045
This commit is contained in:
Manoj Kumar AVM
2014-04-29 22:08:51 -07:00
committed by Ramkumar Radhakrishnan
parent 1b481cb042
commit 001b30942d

View File

@@ -83,7 +83,7 @@ write_int(char const* path, int value)
fd = open(path, O_RDWR); fd = open(path, O_RDWR);
if (fd >= 0) { if (fd >= 0) {
char buffer[20]; char buffer[20];
int bytes = sprintf(buffer, "%d\n", value); int bytes = snprintf(buffer, sizeof(buffer), "%d\n", value);
ssize_t amt = write(fd, buffer, (size_t)bytes); ssize_t amt = write(fd, buffer, (size_t)bytes);
close(fd); close(fd);
return amt == -1 ? -errno : 0; return amt == -1 ? -errno : 0;
@@ -271,6 +271,10 @@ static int open_lights(const struct hw_module_t* module, char const* name,
pthread_once(&g_init, init_globals); pthread_once(&g_init, init_globals);
struct light_device_t *dev = malloc(sizeof(struct light_device_t)); struct light_device_t *dev = malloc(sizeof(struct light_device_t));
if(!dev)
return -ENOMEM;
memset(dev, 0, sizeof(*dev)); memset(dev, 0, sizeof(*dev));
dev->common.tag = HARDWARE_DEVICE_TAG; dev->common.tag = HARDWARE_DEVICE_TAG;