BPF List
 help / color / mirror / Atom feed
* [PATCH] libbpf: fix str_has_sfx()
@ 2022-07-19  9:53 Dan Carpenter
  2022-07-19 17:19 ` Martin KaFai Lau
  2022-07-21 13:00 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 9+ messages in thread
From: Dan Carpenter @ 2022-07-19  9:53 UTC (permalink / raw)
  To: Alexei Starovoitov, Alan Maguire
  Cc: Alexei Starovoitov, Daniel Borkmann, Martin KaFai Lau, Song Liu,
	Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
	Hao Luo, Jiri Olsa, bpf, kernel-janitors

The return from strcmp() is inverted so the it returns true instead
of false and vise versa.

Fixes: a1c9d61b19cb ("libbpf: Improve library identification for uprobe binary path resolution")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
Spotted during review.  *cmp() functions should always have a comparison
to zero.
	if (strcmp(a, b) < 0) {  <-- means a < b
	if (strcmp(a, b) >= 0) { <-- means a >= b
	if (strcmp(a, b) != 0) { <-- means a != b
etc.

 tools/lib/bpf/libbpf_internal.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
index 9cd7829cbe41..008485296a29 100644
--- a/tools/lib/bpf/libbpf_internal.h
+++ b/tools/lib/bpf/libbpf_internal.h
@@ -108,9 +108,9 @@ static inline bool str_has_sfx(const char *str, const char *sfx)
 	size_t str_len = strlen(str);
 	size_t sfx_len = strlen(sfx);
 
-	if (sfx_len <= str_len)
-		return strcmp(str + str_len - sfx_len, sfx);
-	return false;
+	if (sfx_len > str_len)
+		return false;
+	return strcmp(str + str_len - sfx_len, sfx) == 0;
 }
 
 /* Symbol versioning is different between static and shared library.
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-07-28 22:11 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-19  9:53 [PATCH] libbpf: fix str_has_sfx() Dan Carpenter
2022-07-19 17:19 ` Martin KaFai Lau
2022-07-19 17:50   ` Dan Carpenter
2022-07-19 17:54     ` Alexei Starovoitov
2022-07-20  9:11       ` Dan Carpenter
2022-07-19 17:51   ` Alexei Starovoitov
2022-07-20  7:37     ` Alan Maguire
2022-07-28 22:10       ` Andrii Nakryiko
2022-07-21 13:00 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox