libwd/0010-uadk-fix-for-get_str_attr.patch
2023-09-28 09:15:32 +08:00

40 lines
1.0 KiB
Diff

From 3015d495313e86ee8ec72ef4f6ff7984eb05614a Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Tue, 8 Aug 2023 21:22:19 +0800
Subject: [PATCH 10/26] uadk: fix for get_str_attr
If snprintf returns 0, (ret - 1) will be negative and used
as an array index, fix it, also, the int type should be
converted to unsigned int.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
v1/wd.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/v1/wd.c b/v1/wd.c
index e0a86dc..3839304 100644
--- a/v1/wd.c
+++ b/v1/wd.c
@@ -81,7 +81,7 @@ static int get_raw_attr(const char *dev_root, const char *attr,
dev_root, attr);
if (size <= 0) {
WD_ERR("get %s/%s path fail!\n", dev_root, attr);
- return size;
+ return -WD_EINVAL;
}
ptrRet = realpath(attr_file, attr_path);
@@ -140,7 +140,7 @@ static int get_str_attr(struct dev_info *dinfo, const char *attr, char *buf,
return ret;
}
- if ((size_t)ret == buf_sz)
+ if ((__u32)ret == buf_sz)
ret = ret - 1;
buf[ret] = '\0';
--
2.25.1