[][openwrt][common][app][Fix Coverity defects in the switch utility]
[Description]
Fix Coverity defects.
[Release-log]
N/A
Change-Id: Ib97f8fe346f2c26faa55c41b4700902ab60e9a55
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/9828524
diff --git a/feed/app/switch/src/switch_753x.c b/feed/app/switch/src/switch_753x.c
index a2cd8a2..0e7920f 100644
--- a/feed/app/switch/src/switch_753x.c
+++ b/feed/app/switch/src/switch_753x.c
@@ -427,8 +427,8 @@
static void parse_reg_cmd(int argc, char *argv[], int len)
{
- unsigned int val;
- unsigned int off;
+ unsigned int val = 0;
+ unsigned int off = 0;
char *endptr;
int i, j;
@@ -643,6 +643,7 @@
int err = -EINVAL;
FILE *fp = NULL;
char buff[255];
+ char *endptr;
attres = (struct mt753x_attr *)malloc(sizeof(struct mt753x_attr));
if (attres == NULL) {
@@ -756,7 +757,11 @@
}
if (!strcmp(argv[1], "dev")) {
- attres->dev_id = strtoul(argv[2], NULL, 0);
+ errno = 0; /* To distinguish success/failure after call */
+ attres->dev_id = strtoul(argv[2], &endptr, 0);
+ if (errno != 0 || *endptr != '\0')
+ goto error;
+
argv += 2;
argc -= 2;
if (argc < 2)
@@ -1066,7 +1071,7 @@
usage(argv[0]);
} else
usage(argv[0]);
-
+error:
exit_free();
return 0;
#endif