You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2013/06/21 19:59:44 UTC
svn commit: r1495526 -
/commons/proper/net/trunk/src/main/java/org/apache/commons/net/util/SubnetUtils.java
Author: sebb
Date: Fri Jun 21 17:59:44 2013
New Revision: 1495526
URL: http://svn.apache.org/r1495526
Log:
It's tricky following the range check as one end is exclusive and the other is inclusive
Make both ends inclusive and adjust the calling code accordingly
Modified:
commons/proper/net/trunk/src/main/java/org/apache/commons/net/util/SubnetUtils.java
Modified: commons/proper/net/trunk/src/main/java/org/apache/commons/net/util/SubnetUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/util/SubnetUtils.java?rev=1495526&r1=1495525&r2=1495526&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/org/apache/commons/net/util/SubnetUtils.java (original)
+++ commons/proper/net/trunk/src/main/java/org/apache/commons/net/util/SubnetUtils.java Fri Jun 21 17:59:44 2013
@@ -226,7 +226,7 @@ public class SubnetUtils {
address = matchAddress(matcher);
/* Create a binary netmask from the number of bits specification /x */
- int cidrPart = rangeCheck(Integer.parseInt(matcher.group(5)), 0, NBITS);
+ int cidrPart = rangeCheck(Integer.parseInt(matcher.group(5)), 1, NBITS);
for (int j = 0; j < cidrPart; ++j) {
netmask |= (1 << 31-j);
}
@@ -260,7 +260,7 @@ public class SubnetUtils {
private int matchAddress(Matcher matcher) {
int addr = 0;
for (int i = 1; i <= 4; ++i) {
- int n = (rangeCheck(Integer.parseInt(matcher.group(i)), -1, 255));
+ int n = (rangeCheck(Integer.parseInt(matcher.group(i)), 0, 255));
addr |= ((n & 0xff) << 8*(4-i));
}
return addr;
@@ -293,15 +293,15 @@ public class SubnetUtils {
/*
* Convenience function to check integer boundaries.
- * Checks if a value x is in the range (begin,end].
+ * Checks if a value x is in the range [begin,end].
* Returns x if it is in range, throws an exception otherwise.
*/
private int rangeCheck(int value, int begin, int end) {
- if (value > begin && value <= end) { // (begin,end]
+ if (value >= begin && value <= end) { // (begin,end]
return value;
}
- throw new IllegalArgumentException("Value [" + value + "] not in range ("+begin+","+end+"]");
+ throw new IllegalArgumentException("Value [" + value + "] not in range ["+begin+","+end+"]");
}
/*