zookeeper-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maoling <...@git.apache.org>
Subject [GitHub] zookeeper pull request #539: ZOOKEEPER-3058: Do length check first before ac...
Date Sun, 10 Jun 2018 07:19:05 GMT
Github user maoling commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/539#discussion_r194248152
  
    --- Diff: src/java/main/org/apache/jute/Utils.java ---
    @@ -268,15 +268,14 @@ static String toCSVBuffer(byte barr[]) {
             return stream.toByteArray();
         }
         public static int compareBytes(byte b1[], int off1, int len1, byte b2[], int off2,
int len2) {
    -        int i;
    -        for(i=0; i < len1 && i < len2; i++) {
    +        if (len1 != len2) {
    +            return len1 < len2 ? -1 : 1;
    +        }
    +        for(int i=0; i < len1; i++) {
                 if (b1[off1+i] != b2[off2+i]) {
    --- End diff --
    
    no a issue?
    This function is for comparison byte one by one.
    Some UT for understanding:
    zbcd : abcde  --> 1
    abcd :  abce --> 1
    abcd :  abca --> -1
    abcd :  abcde --> 1
    abcd :  abc --> -1


---

Mime
View raw message