diff options
author | Thomas Wolf <thomas.wolf@paranor.ch> | 2017-08-14 08:04:56 +0200 |
---|---|---|
committer | Thomas Wolf <thomas.wolf@paranor.ch> | 2017-08-14 08:04:56 +0200 |
commit | b07db609089749ed49a7f0b1fb3841a8f74110c2 (patch) | |
tree | 813f3a4e4494d3ba2ccce55f090f7f41353e7642 /org.eclipse.jgit/src | |
parent | 4bc539a8141e8099587536620bdc555c2c4cb01e (diff) | |
download | jgit-b07db609089749ed49a7f0b1fb3841a8f74110c2.tar.gz jgit-b07db609089749ed49a7f0b1fb3841a8f74110c2.zip |
Fix off-by-one error in Strings.count()
Change-Id: I0667b1624827d1cf0cc1b81f86c7bb44eafd68a7
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit/src')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/Strings.java | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/Strings.java b/org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/Strings.java index da482fa50a..79df1511d1 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/Strings.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/Strings.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014, Andrey Loskutov <loskutov@gmx.de> + * Copyright (C) 2014, 2017 Andrey Loskutov <loskutov@gmx.de> * and other copyright owners as documented in the project's IP log. * * This program and the accompanying materials are made available @@ -123,12 +123,15 @@ public class Strings { static int count(String s, char c, boolean ignoreFirstLast) { int start = 0; int count = 0; - while (true) { + int length = s.length(); + while (start < length) { start = s.indexOf(c, start); - if (start == -1) + if (start == -1) { break; - if (!ignoreFirstLast || (start != 0 && start != s.length())) + } + if (!ignoreFirstLast || (start != 0 && start != length - 1)) { count++; + } start++; } return count; |