Merge "hqd: Fix Klocwork errors in liblight"
diff --git a/liblight/lights.c b/liblight/lights.c
index 1aa0b58..6fd1290 100644
--- a/liblight/lights.c
+++ b/liblight/lights.c
@@ -83,7 +83,7 @@
     fd = open(path, O_RDWR);
     if (fd >= 0) {
         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);
         close(fd);
         return amt == -1 ? -errno : 0;
@@ -271,6 +271,10 @@
     pthread_once(&g_init, init_globals);
 
     struct light_device_t *dev = malloc(sizeof(struct light_device_t));
+
+    if(!dev)
+        return -ENOMEM;
+
     memset(dev, 0, sizeof(*dev));
 
     dev->common.tag = HARDWARE_DEVICE_TAG;