From 1e7bbde6e99d86c34a128e77af9ddafe0507d8dd Mon Sep 17 00:00:00 2001 From: Jianhua Liu Date: Wed, 11 Oct 2023 22:59:53 +0800 Subject: [PATCH 1/4] src: fix length of register name The length of register name should be initialized. Signed-off-by: Jianhua Liu Signed-off-by: Rongwei Wang --- rdasr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rdasr.c b/rdasr.c index 332da5a..b6f09fa 100644 --- a/rdasr.c +++ b/rdasr.c @@ -223,10 +223,10 @@ void parse(const char *regname) { int status; int op0, op1, cn, cm, op2; - unsigned int len = 0; + unsigned int len = strlen(regname); global_register = (struct register_t *)malloc(sizeof(struct register_t)); - global_register->length = strlen(regname); + global_register->length = len; global_register->name = strdup(regname); /* check the format of register name */ -- Gitee From 5e185cf525c322629c2f5dae7f987c04ae9b26d8 Mon Sep 17 00:00:00 2001 From: Jianhua Liu Date: Wed, 11 Oct 2023 23:03:42 +0800 Subject: [PATCH 2/4] src: replace with fprintf fprintf seems better than printf, especially print error messages. Signed-off-by: Jianhua Liu Signed-off-by: Rongwei Wang --- rdasr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rdasr.c b/rdasr.c index b6f09fa..6cda7c7 100644 --- a/rdasr.c +++ b/rdasr.c @@ -81,7 +81,7 @@ int search(void) FILE *fp; if ((fp = fopen(TABLEPATH, "r")) == NULL) { - printf("%s: No such file or can not read!\n", TABLEPATH); + fprintf(stderr, "%s: No such file or can not read!\n", TABLEPATH); return -1; } @@ -152,7 +152,7 @@ int test_all(void) FILE *fp; if ((fp = fopen(TABLEPATH, "r")) == NULL) { - printf("%s: No such file or can not read!\n", TABLEPATH); + fprintf(stderr, "%s: No such file or can not read!\n", TABLEPATH); return -1; } -- Gitee From 8ecdb3ce25eb680f63816ab967e6924a7f1fe5c6 Mon Sep 17 00:00:00 2001 From: Jianhua Liu Date: Wed, 11 Oct 2023 23:07:37 +0800 Subject: [PATCH 3/4] src: add source link A problem that ".regtable not find" always happen. And users don't know how to do this time. So add .regtable file link and install step when it happens. Signed-off-by: Jianhua Liu Signed-off-by: Rongwei Wang --- rdasr.c | 7 ++++++- wrasr.c | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/rdasr.c b/rdasr.c index 6cda7c7..ba6d977 100644 --- a/rdasr.c +++ b/rdasr.c @@ -81,7 +81,12 @@ int search(void) FILE *fp; if ((fp = fopen(TABLEPATH, "r")) == NULL) { - fprintf(stderr, "%s: No such file or can not read!\n", TABLEPATH); + fprintf(stderr, "%s: No such file or can not read!\n\ + an register table you can find:\n\ + https://github.com/alibaba/system-register-tools/blob/main/registersv8.table\n\ + download and move this configure:\n\ + wget -o ~/.regstable\n\ + or move this file into '/root/' if you are root user!\n", TABLEPATH); return -1; } diff --git a/wrasr.c b/wrasr.c index 4520d24..afc7db5 100644 --- a/wrasr.c +++ b/wrasr.c @@ -102,7 +102,13 @@ int search(void) FILE *fp; if ((fp = fopen(TABLEPATH, "r")) == NULL) { - printf("%s: No such file or can not read!\n", TABLEPATH); + fprintf(stderr, "%s: No such file or can not read!\n\ + an register table you can find:\n\ + https://github.com/alibaba/system-register-tools/blob/main/registersv8.table\n\ + download and move this configure:\n\ + wget -o ~/.regstable\n\ + or move this file into '/root/' if you are root user!\n", TABLEPATH); + return -1; } -- Gitee From 9050cc40c02163e4c14a8df1f2a13ee9763f0c45 Mon Sep 17 00:00:00 2001 From: Jianhua Liu Date: Wed, 11 Oct 2023 23:15:43 +0800 Subject: [PATCH 4/4] src: replace with NAME_MAX Here replacing with NAME_MAX (from limits.h) to improve readability. Signed-off-by: Jianhua Liu --- rdasr.c | 3 ++- wrasr.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/rdasr.c b/rdasr.c index ba6d977..10bb240 100644 --- a/rdasr.c +++ b/rdasr.c @@ -18,6 +18,7 @@ #include #include #include +#include #include "version.h" #include "sysreg.h" @@ -277,7 +278,7 @@ int main(int argc, char *argv[]) unsigned int highbit = 63, lowbit = 0; unsigned long arg; char *endarg; - char msr_file_name[64]; + char msr_file_name[NAME_MAX]; program = argv[0]; /* check the usage of program */ diff --git a/wrasr.c b/wrasr.c index afc7db5..421a0f8 100644 --- a/wrasr.c +++ b/wrasr.c @@ -15,6 +15,7 @@ #include #include #include +#include #include "version.h" #include "sysreg.h" @@ -192,7 +193,7 @@ int main(int argc, char *argv[]) unsigned int highbit = 63, lowbit = 0; unsigned long arg; char *endarg; - char msr_file_name[64]; + char msr_file_name[NAME_MAX]; program = argv[0]; init(); -- Gitee