Skip to content

Commit 2a65ddb

Browse files
committed
feat(BitCount BitPos):add bitMode:BYTE|BIT
Signed-off-by: gitsrc <34047788+gitsrc@users.noreply.github.com>
1 parent 41a1243 commit 2a65ddb

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

ledis/t_kv.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,14 @@ func numberBitCount(i uint32) uint32 {
681681

682682
// validateRange
683683
func validateRange(start, end, length int) (int, int, error) {
684+
// Check if start or end exceed length before dealing with negative index
685+
if start >= length {
686+
return 0, 0, fmt.Errorf("byte range out of bounds")
687+
}
688+
if end >= length {
689+
return 0, 0, fmt.Errorf("byte range out of bounds")
690+
}
691+
684692
// deal with negative index
685693
if start < 0 {
686694
start = length + start
@@ -697,14 +705,22 @@ func validateRange(start, end, length int) (int, int, error) {
697705
end = length - 1
698706
}
699707
if start > end {
700-
return 0, 0, fmt.Errorf("ERR invalid range: start > end")
708+
return 0, 0, fmt.Errorf("byte invalid range: start > end")
701709
}
702710

703711
return start, end, nil
704712
}
705713

706714
// validateBitRange
707715
func validateBitRange(start, end, bitLength int) (int, int, error) {
716+
// Check if start or end exceed bitLength before dealing with negative index
717+
if start >= bitLength {
718+
return 0, 0, fmt.Errorf("bit range out of bounds")
719+
}
720+
if end >= bitLength {
721+
return 0, 0, fmt.Errorf("bit range out of bounds")
722+
}
723+
708724
// deal with negative index
709725
if start < 0 {
710726
start = bitLength + start

0 commit comments

Comments
 (0)