From c689c2c67fa5519b510fe22b7f8fe61b4aa08b40 Mon Sep 17 00:00:00 2001 From: David Lin Date: Sun, 8 Mar 2020 00:48:32 +0800 Subject: [PATCH] Fixed a hidden stack overflow bug 'memset' should been next step after 'NULL' judge --- bsp/fh8620/drivers/pwm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bsp/fh8620/drivers/pwm.c b/bsp/fh8620/drivers/pwm.c index a9d2645631..ff02a5a6db 100644 --- a/bsp/fh8620/drivers/pwm.c +++ b/bsp/fh8620/drivers/pwm.c @@ -186,12 +186,13 @@ int fh_pwm_probe(void *priv_data) PWM_Enable(pwm_obj, RT_FALSE); pwm_dev = rt_malloc(sizeof(struct rt_device)); - rt_memset(pwm_dev, 0, sizeof(struct rt_device)); if (pwm_dev == RT_NULL) { rt_kprintf("ERROR: %s rt_device malloc failed\n", __func__); } + + rt_memset(pwm_dev, 0, sizeof(struct rt_device)); pwm_dev->user_data = &pwm_drv; pwm_dev->open =fh_pwm_open;