public inbox for ntfs3@lists.linux.dev
 help / color / mirror / Atom feed
From: Mark Harmstone <mark@harmstone.com>
To: ntfs3@lists.linux.dev
Cc: Mark Harmstone <mark@harmstone.com>
Subject: [PATCH] fs/ntfs3: Fix logic in ntfs_cmp_names_cpu
Date: Tue, 28 Sep 2021 19:33:00 +0100	[thread overview]
Message-ID: <20210928183300.12946-1-mark@harmstone.com> (raw)

I'm not quite sure what was intended by the logic in ntfs_cmp_names_cpu,
but it was broken when comparing case-insensitively. If the strings
matched but differ in case, diff1 would be non-zero, meaning that the
function would always return a non-zero value.

Signed-off-by: Mark Harmstone <mark@harmstone.com>
---
 fs/ntfs3/upcase.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/fs/ntfs3/upcase.c b/fs/ntfs3/upcase.c
index b5e8256fd710..dd28c2133a4c 100644
--- a/fs/ntfs3/upcase.c
+++ b/fs/ntfs3/upcase.c
@@ -74,31 +74,29 @@ int ntfs_cmp_names_cpu(const struct cpu_str *uni1, const struct le_str *uni2,
 	size_t l1 = uni1->len;
 	size_t l2 = uni2->len;
 	size_t len = min(l1, l2);
-	int diff1 = 0;
-	int diff2;
+	int diff;
 
 	if (!bothcase && upcase)
 		goto case_insentive;
 
 	for (; len; s1++, s2++, len--) {
-		diff1 = *s1 - le16_to_cpu(*s2);
-		if (diff1) {
+		diff = *s1 - le16_to_cpu(*s2);
+		if (diff) {
 			if (bothcase && upcase)
 				goto case_insentive;
 
-			return diff1;
+			return diff;
 		}
 	}
 	return l1 - l2;
 
 case_insentive:
 	for (; len; s1++, s2++, len--) {
-		diff2 = upcase_unicode_char(upcase, *s1) -
+		diff = upcase_unicode_char(upcase, *s1) -
 			upcase_unicode_char(upcase, le16_to_cpu(*s2));
-		if (diff2)
-			return diff2;
+		if (diff)
+			return diff;
 	}
 
-	diff2 = l1 - l2;
-	return diff2 ? diff2 : diff1;
+	return l1 - l2;
 }
-- 
2.31.1


             reply	other threads:[~2021-09-28 18:33 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-28 18:33 Mark Harmstone [this message]
2021-09-28 19:11 ` [PATCH] fs/ntfs3: Fix logic in ntfs_cmp_names_cpu Kari Argillander
2021-09-28 22:07 ` Kari Argillander
2021-09-28 23:27   ` Mark Harmstone
2021-10-04 18:25     ` Mark Harmstone
2021-10-06 14:37       ` Konstantin Komarov
2021-10-06 17:03         ` Mark Harmstone
2021-10-07 14:33           ` Konstantin Komarov
2021-10-07 18:26             ` Mark Harmstone
2021-10-07 20:12               ` Kari Argillander
2021-10-07 20:34                 ` Mark Harmstone
2021-10-08  5:51                   ` Kari Argillander

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210928183300.12946-1-mark@harmstone.com \
    --to=mark@harmstone.com \
    --cc=ntfs3@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox