lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20170412005215.30135-9-acme@kernel.org>
Date:   Tue, 11 Apr 2017 21:52:05 -0300
From:   Arnaldo Carvalho de Melo <acme@...nel.org>
To:     Ingo Molnar <mingo@...nel.org>
Cc:     linux-kernel@...r.kernel.org,
        Arnaldo Carvalho de Melo <acme@...hat.com>,
        Jiri Olsa <jolsa@...nel.org>,
        Namhyung Kim <namhyung@...nel.org>,
        Taeung Song <treeze.taeung@...il.com>
Subject: [PATCH 08/18] perf string: Simplify ltrim() implementation

From: Arnaldo Carvalho de Melo <acme@...hat.com>

We don't need to use strlen(), a var, or check for the end explicitely,
isspace('\0') is false:

  [acme@...et c]$ cat ltrim.c
  #include <ctype.h>
  #include <stdio.h>

  static char *ltrim(char *s)
  {
	  while (isspace(*s))
		  ++s;
	  return s;
  }

  int main(void)
  {
	  printf("ltrim(\"\")='%s'\n", ltrim(""));
	  return 0;
  }
  [acme@...et c]$ ./ltrim
  ltrim("")=''
  [acme@...et c]$

Cc: Jiri Olsa <jolsa@...nel.org>
Cc: Namhyung Kim <namhyung@...nel.org>
Cc: Taeung Song <treeze.taeung@...il.com>
Link: http://lkml.kernel.org/n/tip-w3nk0x3pai2vojk2ab6kdvaw@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@...hat.com>
---
 tools/perf/util/string.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c
index bddca519dd58..e8feb142c9c9 100644
--- a/tools/perf/util/string.c
+++ b/tools/perf/util/string.c
@@ -322,12 +322,8 @@ char *strxfrchar(char *s, char from, char to)
  */
 char *ltrim(char *s)
 {
-	int len = strlen(s);
-
-	while (len && isspace(*s)) {
-		len--;
+	while (isspace(*s))
 		s++;
-	}
 
 	return s;
 }
-- 
2.9.3

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ