[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJFMrCFqMN85izJ_BEsqMx5PV+RbjJDmR468hTa-Mt1bQvhXNA@mail.gmail.com>
Date: Wed, 18 Mar 2015 23:40:10 +0530
From: Arjun Sreedharan <arjun024@...il.com>
To: Bernd Petrovitsch <bernd@...rovitsch.priv.at>
Cc: Ingo Molnar <mingo@...nel.org>, "H. Peter Anvin" <hpa@...or.com>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, x86@...nel.org,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] x86,boot: standardize strcmp()
On 18 March 2015 at 07:06, Bernd Petrovitsch <bernd@...rovitsch.priv.at> wrote:
> On Die, 2015-03-17 at 19:43 +0530, Arjun Sreedharan wrote:
> [...]
>> On a related note, IMO strcmp() should return {-1,0,1} since many
>> programmers just expect this behavior. just my opinion.
>
> -ENOPATCH.
Here's a patch
-- >8 --
Subject: [PATCH] arm,x86: limit strcmp() rc to {-1,0,1}
Signed-off-by: Arjun Sreedharan <arjun024@...il.com>
---
arch/arm/boot/compressed/string.c | 2 +-
arch/x86/boot/string.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/arm/boot/compressed/string.c
b/arch/arm/boot/compressed/string.c
index 36e53ef..e48df86 100644
--- a/arch/arm/boot/compressed/string.c
+++ b/arch/arm/boot/compressed/string.c
@@ -88,7 +88,7 @@ int strcmp(const char *cs, const char *ct)
c2 = *ct++;
res = c1 - c2;
if (res)
- break;
+ return res < 0 ? -1 : 1;
} while (c1);
return res;
}
diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c
index 318b846..6eb333e 100644
--- a/arch/x86/boot/string.c
+++ b/arch/x86/boot/string.c
@@ -32,7 +32,7 @@ int strcmp(const char *str1, const char *str2)
while (*s1 || *s2) {
delta = *s1 - *s2;
if (delta)
- return delta;
+ return delta < 0 ? -1 : 1;
s1++;
s2++;
}
--
>
> MfG,
> Bernd
> --
> "I dislike type abstraction if it has no real reason. And saving
> on typing is not a good reason - if your typing speed is the main
> issue when you're coding, you're doing something seriously wrong."
> - Linus Torvalds
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists