diff options
author | Christian Halstrick <christian.halstrick@sap.com> | 2017-08-16 06:24:43 -0400 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org <gerrit@eclipse.org> | 2017-08-16 06:24:43 -0400 |
commit | be767fd7d90116140132fd35c858a124b695bae1 (patch) | |
tree | f17858c5acc69452f8a127ff15f427eae8a9df17 /org.eclipse.jgit | |
parent | c71af0c73a06f298a983a7ff0c3e0f3bfed5181a (diff) | |
parent | b07db609089749ed49a7f0b1fb3841a8f74110c2 (diff) | |
download | jgit-be767fd7d90116140132fd35c858a124b695bae1.tar.gz jgit-be767fd7d90116140132fd35c858a124b695bae1.zip |
Merge "Fix off-by-one error in Strings.count()"
Diffstat (limited to 'org.eclipse.jgit')
-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; |