All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arjun Sreedharan <arjun024@gmail.com>
To: Bernd Petrovitsch <bernd@petrovitsch.priv.at>
Cc: Ingo Molnar <mingo@kernel.org>, "H. Peter Anvin" <hpa@zytor.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>,
	x86@kernel.org,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] x86,boot: standardize strcmp()
Date: Wed, 18 Mar 2015 23:40:10 +0530	[thread overview]
Message-ID: <CAJFMrCFqMN85izJ_BEsqMx5PV+RbjJDmR468hTa-Mt1bQvhXNA@mail.gmail.com> (raw)
In-Reply-To: <1426642573.20946.2.camel@thorin>

On 18 March 2015 at 07:06, Bernd Petrovitsch <bernd@petrovitsch.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@gmail.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
>

  reply	other threads:[~2015-03-18 18:10 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-16 15:37 [PATCH] x86,boot: standardize strcmp() Arjun Sreedharan
2015-03-16 18:16 ` Borislav Petkov
2015-03-17  7:46 ` Ingo Molnar
2015-03-17 14:13   ` Arjun Sreedharan
2015-03-18  1:36     ` Bernd Petrovitsch
2015-03-18 18:10       ` Arjun Sreedharan [this message]
2015-03-18 18:37       ` Arjun Sreedharan
2015-03-19 17:34     ` H. Peter Anvin
2015-03-20 11:42       ` Bernd Petrovitsch
2015-03-17 14:28   ` Borislav Petkov
2015-03-23 12:23 ` [tip:x86/boot] x86/boot: Standardize strcmp() tip-bot for Arjun Sreedharan

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=CAJFMrCFqMN85izJ_BEsqMx5PV+RbjJDmR468hTa-Mt1bQvhXNA@mail.gmail.com \
    --to=arjun024@gmail.com \
    --cc=bernd@petrovitsch.priv.at \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.