From 5a882c718480d69755ca49063856da7eacbee997 Mon Sep 17 00:00:00 2001 From: Nguyen Anh Quynh Date: Tue, 12 Feb 2019 20:18:13 +0800 Subject: [PATCH] cstest: protopye for trim_str & replace_hex --- suite/cstest/include/helper.h | 4 ++-- suite/cstest/src/helper.c | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/suite/cstest/include/helper.h b/suite/cstest/include/helper.h index 00bba00a..bea8d1d4 100644 --- a/suite/cstest/include/helper.h +++ b/suite/cstest/include/helper.h @@ -13,8 +13,8 @@ char **split(char *str, char *delim, int *size); void print_strs(char **list_str, int size); void free_strs(char **list_str, int size); void add_str(char **src, const char *format, ...); -void trim_str(char src[]); -void replace_hex(char src[]); +void trim_str(char *src); +void replace_hex(char *src); const char *get_filename_ext(const char *filename); char *readfile(const char *filename); diff --git a/suite/cstest/src/helper.c b/suite/cstest/src/helper.c index 5c0397d7..2869b1ed 100644 --- a/suite/cstest/src/helper.c +++ b/suite/cstest/src/helper.c @@ -103,7 +103,7 @@ void add_str(char **src, const char *format, ...) free(tmp); } -void replace_hex(char src[]) +void replace_hex(char *src) { char *tmp, *result, *found, *origin; int i; @@ -137,6 +137,7 @@ void replace_hex(char src[]) fprintf(stderr, "[ Error ] --- Buffer Overflow in replace_hex()\n"); exit(-1); } + strcpy(src, result); free(result); free(origin); @@ -172,7 +173,7 @@ void listdir(const char *name, char ***files, int *num_files) closedir(dir); } -void trim_str(char str[]) +void trim_str(char *str) { char tmp[MAXMEM]; int start, end, j, i; @@ -185,6 +186,7 @@ void trim_str(char str[]) for (i=start; i<=end; ++i) tmp[j++] = str[i]; + tmp[j] = '\0'; strcpy(str, tmp);