diff mbox series

lib: fwts_wakealarm: memset a rtc_tm struct to keep static analyzers happy

Message ID 20200407171945.919398-1-colin.king@canonical.com
State Accepted
Headers show
Series lib: fwts_wakealarm: memset a rtc_tm struct to keep static analyzers happy | expand

Commit Message

Colin Ian King April 7, 2020, 5:19 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

Coverity throws a warning of a potential use of unitialized fields
in the rtc_tm struct, so memset it to zero before calling the ioctl.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_wakealarm.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Alex Hung April 7, 2020, 6:09 p.m. UTC | #1
On 2020-04-07 11:19 a.m., Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Coverity throws a warning of a potential use of unitialized fields
> in the rtc_tm struct, so memset it to zero before calling the ioctl.
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/src/fwts_wakealarm.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/src/lib/src/fwts_wakealarm.c b/src/lib/src/fwts_wakealarm.c
> index 43718707..5c4c9375 100644
> --- a/src/lib/src/fwts_wakealarm.c
> +++ b/src/lib/src/fwts_wakealarm.c
> @@ -41,6 +41,7 @@ int fwts_wakealarm_get(fwts_framework *fw, struct rtc_time *rtc_tm)
>  	int fd;
>  	int ret = FWTS_OK;
>  
> +	(void)memset(rtc_tm, 0, sizeof(*rtc_tm));
>  	if ((fd = open(fwts_rtc, O_RDWR)) < 0) {
>  		fwts_log_error(fw, "Cannot access Real Time Clock device %s.", fwts_rtc);
>  		return FWTS_ERROR;
> @@ -92,6 +93,7 @@ int fwts_wakealarm_trigger(fwts_framework *fw, const uint32_t seconds)
>  		return FWTS_ERROR;
>  	}
>  
> +	(void)memset(&rtc_tm, 0, sizeof(rtc_tm));
>  	if (ioctl(fd, RTC_RD_TIME, &rtc_tm) < 0) {
>  		fwts_log_error(fw, "Cannot read Real Time Clock with ioctl RTC_RD_TIME %s.", fwts_rtc);
>  		ret = FWTS_ERROR;
> 


Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu April 8, 2020, 6:43 a.m. UTC | #2
On 4/8/20 1:19 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Coverity throws a warning of a potential use of unitialized fields
> in the rtc_tm struct, so memset it to zero before calling the ioctl.
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/src/fwts_wakealarm.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/src/lib/src/fwts_wakealarm.c b/src/lib/src/fwts_wakealarm.c
> index 43718707..5c4c9375 100644
> --- a/src/lib/src/fwts_wakealarm.c
> +++ b/src/lib/src/fwts_wakealarm.c
> @@ -41,6 +41,7 @@ int fwts_wakealarm_get(fwts_framework *fw, struct rtc_time *rtc_tm)
>  	int fd;
>  	int ret = FWTS_OK;
>  
> +	(void)memset(rtc_tm, 0, sizeof(*rtc_tm));
>  	if ((fd = open(fwts_rtc, O_RDWR)) < 0) {
>  		fwts_log_error(fw, "Cannot access Real Time Clock device %s.", fwts_rtc);
>  		return FWTS_ERROR;
> @@ -92,6 +93,7 @@ int fwts_wakealarm_trigger(fwts_framework *fw, const uint32_t seconds)
>  		return FWTS_ERROR;
>  	}
>  
> +	(void)memset(&rtc_tm, 0, sizeof(rtc_tm));
>  	if (ioctl(fd, RTC_RD_TIME, &rtc_tm) < 0) {
>  		fwts_log_error(fw, "Cannot read Real Time Clock with ioctl RTC_RD_TIME %s.", fwts_rtc);
>  		ret = FWTS_ERROR;
> 


Acked-by: Ivan Hu <ivan.hu@canonical.com>
diff mbox series

Patch

diff --git a/src/lib/src/fwts_wakealarm.c b/src/lib/src/fwts_wakealarm.c
index 43718707..5c4c9375 100644
--- a/src/lib/src/fwts_wakealarm.c
+++ b/src/lib/src/fwts_wakealarm.c
@@ -41,6 +41,7 @@  int fwts_wakealarm_get(fwts_framework *fw, struct rtc_time *rtc_tm)
 	int fd;
 	int ret = FWTS_OK;
 
+	(void)memset(rtc_tm, 0, sizeof(*rtc_tm));
 	if ((fd = open(fwts_rtc, O_RDWR)) < 0) {
 		fwts_log_error(fw, "Cannot access Real Time Clock device %s.", fwts_rtc);
 		return FWTS_ERROR;
@@ -92,6 +93,7 @@  int fwts_wakealarm_trigger(fwts_framework *fw, const uint32_t seconds)
 		return FWTS_ERROR;
 	}
 
+	(void)memset(&rtc_tm, 0, sizeof(rtc_tm));
 	if (ioctl(fd, RTC_RD_TIME, &rtc_tm) < 0) {
 		fwts_log_error(fw, "Cannot read Real Time Clock with ioctl RTC_RD_TIME %s.", fwts_rtc);
 		ret = FWTS_ERROR;