From 989e8ac48f561edf5e1219a9dd61117e7267b6e9 Mon Sep 17 00:00:00 2001 From: Petro Karashchenko Date: Sun, 27 Mar 2022 21:46:49 +0200 Subject: [PATCH] fs/romfs: fix size of pointer during memory allocation Signed-off-by: Petro Karashchenko --- fs/romfs/fs_romfsutil.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/fs/romfs/fs_romfsutil.c b/fs/romfs/fs_romfsutil.c index a5c5ce34ce..1d4d91c808 100644 --- a/fs/romfs/fs_romfsutil.c +++ b/fs/romfs/fs_romfsutil.c @@ -314,8 +314,7 @@ static inline int romfs_searchdir(FAR struct romfs_mountpt_s *rm, FAR struct romfs_nodeinfo_s **cnodeinfo; cnodeinfo = bsearch(entryname, nodeinfo->rn_child, nodeinfo->rn_count, - sizeof(struct romfs_nodeinfo_s *), - romfs_nodeinfo_search); + sizeof(*nodeinfo->rn_child), romfs_nodeinfo_search); if (cnodeinfo) { memcpy(nodeinfo, *cnodeinfo, sizeof(*nodeinfo)); @@ -441,9 +440,8 @@ static int romfs_cachenode(FAR struct romfs_mountpt_s *rm, { FAR void *tmp; - tmp = kmm_realloc(nodeinfo->rn_child, - (num + NODEINFO_NINCR) * - sizeof(struct romfs_nodeinfo_s *)); + tmp = kmm_realloc(nodeinfo->rn_child, (num + NODEINFO_NINCR) * + sizeof(*nodeinfo->rn_child)); if (tmp == NULL) { return -ENOMEM; @@ -451,7 +449,7 @@ static int romfs_cachenode(FAR struct romfs_mountpt_s *rm, nodeinfo->rn_child = tmp; memset(nodeinfo->rn_child + num, 0, NODEINFO_NINCR * - sizeof(struct romfs_nodeinfo_s *)); + sizeof(*nodeinfo->rn_child)); num += NODEINFO_NINCR; } @@ -478,8 +476,7 @@ static int romfs_cachenode(FAR struct romfs_mountpt_s *rm, if (nodeinfo->rn_count > 1) { qsort(nodeinfo->rn_child, nodeinfo->rn_count, - sizeof(struct romfs_nodeinfo_s *), - romfs_nodeinfo_compare); + sizeof(*nodeinfo->rn_child), romfs_nodeinfo_compare); } return 0;