From cdbf5c6ebe43b597038854e4d0d5ceef2a93e0ac Mon Sep 17 00:00:00 2001 From: wangmingrong1 Date: Tue, 26 Nov 2024 11:12:07 +0800 Subject: [PATCH] Fix compilation errors CC: gcov.c gcov.c: In function 'gcov_stdout_dump': gcov.c:146:50: error: passing argument 3 of '__gcov_info_to_gcda' from incompatible pointer type [-Werror=incompatible-pointer-types] 146 | __gcov_info_to_gcda(info, stdout_filename, stdout_dump, NULL, &arg); | ^~~~~~~~~~~ | | | void (*)(const void *, size_t, void *) {aka void (*)(const void *, long unsigned int, void *)} In file included from gcov.c:25: /mnt/vela/github/NX/nuttx/include/gcov.h:139:44: note: expected 'void (*)(const void *, unsigned int, void *)' but argument is of type 'void (*)(const void *, size_t, void *)' {aka 'void (*)(const void *, long unsigned int, void *)'} 139 | FAR void (*dump)(FAR const void *, | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~ 140 | unsigned int, FAR void *), | ~~~~~~~~~~~~~~~~~~~~~~~~~ libgcc/gcov.c: In function 'gcov_process_path.constprop': libgcc/gcov.c:235:29: error: 'filename' may be used uninitialized [-Werror=maybe-uninitialized] 235 | tokens[token_count++] = filename; | ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~ libgcc/gcov.c:189:13: note: 'filename' was declared here 189 | FAR char *filename; Signed-off-by: wangmingrong1 --- include/gcov.h | 2 +- libs/libbuiltin/libgcc/gcov.c | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/include/gcov.h b/include/gcov.h index 1faad7a9a87..3c6251b82ce 100644 --- a/include/gcov.h +++ b/include/gcov.h @@ -137,7 +137,7 @@ extern void __gcov_info_to_gcda(FAR const struct gcov_info *info, FAR void (*filename)(FAR const char *, FAR void *), FAR void (*dump)(FAR const void *, - unsigned int, FAR void *), + size_t, FAR void *), FAR void *(*allocate)(unsigned int, FAR void *), FAR void *arg); diff --git a/libs/libbuiltin/libgcc/gcov.c b/libs/libbuiltin/libgcc/gcov.c index a98ae36cd86..eac1c3c5394 100644 --- a/libs/libbuiltin/libgcc/gcov.c +++ b/libs/libbuiltin/libgcc/gcov.c @@ -205,6 +205,11 @@ static int gcov_process_path(FAR char *prefix, int strip, prefix_count = token_count; token = strtok(path, "/"); + if (token == NULL) + { + return -EINVAL; + } + while (token != NULL) { filename = token; @@ -315,10 +320,23 @@ void __gcov_dump(void) FAR struct gcov_info *info; FAR const char *strip = getenv("GCOV_PREFIX_STRIP"); FAR const char *prefix = getenv("GCOV_PREFIX"); - FAR char *prefix2 = strdup(prefix); FAR char new_path[PATH_MAX]; + FAR char *prefix2; int ret; + if (prefix == NULL) + { + syslog(LOG_ERR, "No path prefix specified"); + return; + } + + prefix2 = strdup(prefix); + if (prefix2 == NULL) + { + syslog(LOG_ERR, "gcov alloc failed!"); + return; + } + for (info = __gcov_info_start; info; info = info->next) { FAR char *filename; @@ -401,7 +419,7 @@ void __gcov_filename_to_gcfn(FAR const char *filename, void __gcov_info_to_gcda(FAR const struct gcov_info *info, FAR void (*filename_fn)(FAR const char *, FAR void *), - FAR void (*dump_fn)(FAR const void *, unsigned int, + FAR void (*dump_fn)(FAR const void *, size_t, FAR void *), FAR void *(*allocate_fn)(unsigned int, FAR void *), FAR void *arg)