Using `entry_of_file_with_name' returns incorrect result

Message ID 20220425170123.1971444-1-guillermo.e.martinez@oracle.com
State New
Headers
Series Using `entry_of_file_with_name' returns incorrect result |

Commit Message

Guillermo E. Martinez April 25, 2022, 5:01 p.m. UTC
  Hello libabigail team,

This patch corrects the returning value for `entry_of_file_with_name'
function when more than one file in a given directory has a same suffix,

Comments will be appreciated.

Kind Regards,
Guillermo

Function `entry_of_file_with_name' uses `string_ends_with' to test if a
given `fts_path' member of `FTSENT' structure match with `fname'
argument, this result is not correct when in the current directory there
are file with names: "./rmdir-xyx", "./dir-xyz" it returns true for both
files, this patch fixes this ambiguity using `basename' instead.

	* src/abg-tools-utils.cc (entry_of_file_with_name): Replace
	call `string_ends_with' by `basename'.
---
 src/abg-tools-utils.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Dodji Seketeli May 2, 2022, 3:29 p.m. UTC | #1
Hello Guillermo,

"Guillermo E. Martinez via Libabigail" <libabigail@sourceware.org> a
écrit:

[...]

> 	* src/abg-tools-utils.cc (entry_of_file_with_name): Replace
> 	call `string_ends_with' by `basename'.

Applied to master, thanks!

[...]

Cheers,
  

Patch

diff --git a/src/abg-tools-utils.cc b/src/abg-tools-utils.cc
index e94c3003..1f0f6fa8 100644
--- a/src/abg-tools-utils.cc
+++ b/src/abg-tools-utils.cc
@@ -2141,8 +2141,8 @@  entry_of_file_with_name(const FTSENT *entry,
       || entry->fts_info == FTS_NS)
     return false;
 
-  string fpath = entry->fts_path;
-  if (string_ends_with(fpath, fname))
+  string fpath = ::basename(entry->fts_path);
+  if (fpath == fname)
     return true;
   return false;
 }