diff options
| author | Manoj Kumar AVM <manojavm@codeaurora.org> | 2014-10-02 05:16:35 +0200 |
|---|---|---|
| committer | Dave Daynard <nardholio@gmail.com> | 2015-07-07 13:38:14 -0400 |
| commit | 357b9bd38fea25d49547ebb8d7737e593f131404 (patch) | |
| tree | 7fe16489cb3f0e36a98b6e44c45c02a7e50a0d55 | |
| parent | 5e6152ba34bc3959abe2c705b31f4a60756c9b86 (diff) | |
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: If408be6040481f5edda78cfeed477b30ab5b5e73
| -rw-r--r-- | liblights/lights.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/liblights/lights.c b/liblights/lights.c index 2e17387..83b2107 100644 --- a/liblights/lights.c +++ b/liblights/lights.c @@ -1,6 +1,6 @@ /* - * Copyright (C) 2008 The Android Open Source Project - * Copyright (C) 2012 The CyanogenMod Project + * Copyright (C) 2008 The Android Open Source Project. + * Copyright (C) 2014 The CyanogenMod Project. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -66,8 +66,8 @@ static int write_int(char const *path, int value) if (fd >= 0) { char buffer[20]; - int bytes = sprintf(buffer, "%d\n", value); - int amt = write(fd, buffer, bytes); + 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; } else { @@ -374,6 +374,10 @@ static int open_lights(const struct hw_module_t *module, char const *name, pthread_once(&g_init, init_g_lock); 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; |
