diff --git a/client/tablet.go b/client/tablet.go index e161ddc..04d828b 100644 --- a/client/tablet.go +++ b/client/tablet.go @@ -110,11 +110,11 @@ func (t *Tablet) SetTimestamp(timestamp int64, rowIndex int) { func (t *Tablet) SetValueAt(value interface{}, columnIndex, rowIndex int) error { - if columnIndex < 0 || columnIndex > len(t.measurementSchemas) { + if columnIndex < 0 || columnIndex >= len(t.measurementSchemas) { return fmt.Errorf("illegal argument columnIndex %d", columnIndex) } - if rowIndex < 0 || rowIndex > t.maxRowNumber { + if rowIndex < 0 || rowIndex >= t.maxRowNumber { return fmt.Errorf("illegal argument rowIndex %d", rowIndex) } @@ -221,11 +221,11 @@ func (t *Tablet) GetMaxRowNumber() int { } func (t *Tablet) GetValueAt(columnIndex, rowIndex int) (interface{}, error) { - if columnIndex < 0 || columnIndex > len(t.measurementSchemas) { + if columnIndex < 0 || columnIndex >= len(t.measurementSchemas) { return nil, fmt.Errorf("illegal argument columnIndex %d", columnIndex) } - if rowIndex < 0 || rowIndex > t.maxRowNumber { + if rowIndex < 0 || rowIndex >= t.maxRowNumber { return nil, fmt.Errorf("illegal argument rowIndex %d", rowIndex) } diff --git a/client/tablet_test.go b/client/tablet_test.go index b19f34a..cd01d72 100644 --- a/client/tablet_test.go +++ b/client/tablet_test.go @@ -224,6 +224,22 @@ func TestTablet_SetValueAt(t *testing.T) { rowIndex: 0, }, wantErr: true, + }, { + name: "columnIndex-out-of-range-boundary", + args: args{ + value: 0, + columnIndex: 10, + rowIndex: 0, + }, + wantErr: true, + }, { + name: "rowIndex-out-of-range-boundary", + args: args{ + value: 0, + columnIndex: 0, + rowIndex: 1, + }, + wantErr: true, }, { name: "restart_count", args: args{ @@ -410,6 +426,20 @@ func TestTablet_GetValueAt(t *testing.T) { }, want: int64(1608268702780), wantErr: false, + }, { + name: "columnIndex-out-of-range-boundary", + args: args{ + columnIndex: 10, + rowIndex: 0, + }, + wantErr: true, + }, { + name: "rowIndex-out-of-range-boundary", + args: args{ + columnIndex: 0, + rowIndex: 1, + }, + wantErr: true, }, } if tablet, err := createTablet(1); err == nil {