[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] remove useless null pointer check
From: |
Matteo Croce |
Subject: |
[PATCH] remove useless null pointer check |
Date: |
Mon, 30 Sep 2024 15:51:09 +0200 |
From: Matteo Croce <teknoraver@meta.com>
The null check in info_attach_exclist() is useless, because there is no
way that 'dir' is an invalid pointer.
If it was, the crash would have already occourred two lines above:
if (dir->exclude_list)
This also generates the following warning:
exclist.c: In function ‘info_attach_exclist’:
exclist.c:83:11: error: check of ‘dir’ for NULL after already dereferencing
it [-Werror=analyzer-deref-before-check]
83 | if (faccessat (dir ? dir->fd : chdir_fd, file->name, F_OK, 0)
== 0)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Fix it by assuming that 'dir' is valid.
---
src/exclist.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/exclist.c b/src/exclist.c
index 6c1a3dfd..6585ac1c 100644
--- a/src/exclist.c
+++ b/src/exclist.c
@@ -80,7 +80,7 @@ info_attach_exclist (struct tar_stat_info *dir)
return;
for (file = excfile_head; file; file = file->next)
{
- if (faccessat (dir ? dir->fd : chdir_fd, file->name, F_OK, 0) == 0)
+ if (faccessat (dir->fd, file->name, F_OK, 0) == 0)
{
FILE *fp;
struct exclude *ex = NULL;
--
2.46.2
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] remove useless null pointer check,
Matteo Croce <=