Skip to content

Commit d4203d1

Browse files
committed
Fix ArrayStack cursor bug
1 parent 460f6e9 commit d4203d1

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

pipeline.go

+8-11
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,10 @@ func (r *Pipeline) writeTo(w io.Writer) (int64, replyType, error) {
310310
}
311311

312312
isNewArray := typ == '*'
313+
314+
var n int
315+
n, r.err = w.Write(s)
316+
incrRead()
313317
var newArraySize int
314318
if isNewArray {
315319
var err error
@@ -322,17 +326,6 @@ func (r *Pipeline) writeTo(w io.Writer) (int64, replyType, error) {
322326
r.arrayStack = append(r.arrayStack, newArraySize)
323327
}
324328
}
325-
326-
var n int
327-
n, r.err = w.Write(s)
328-
if !isNewArray {
329-
// On new arrays, we don't want to advance any state
330-
// as we've just modified the array stack.
331-
incrRead()
332-
} else if newArraySize == 0 {
333-
// Nil array, so we want to advance pipeline.
334-
incrRead()
335-
}
336329
return int64(n), typ, r.err
337330
case replyTypeBulkString:
338331
// Bulk string
@@ -420,6 +413,10 @@ func (r *Pipeline) ArrayLength() (int, error) {
420413
return gotN, nil
421414
}
422415

416+
if len(r.arrayStack) == 0 {
417+
return 0, fmt.Errorf("bug: array stack not set")
418+
}
419+
423420
// Sanity check that we've populated the array stack correctly.
424421
if r.arrayStack[len(r.arrayStack)-1] != gotN {
425422
// This should be impossible.

0 commit comments

Comments
 (0)