From 50a9a3e4474ff0ad9b17ffaab58645bb7722dbda Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sun, 17 May 2020 17:08:52 -0700 Subject: [PATCH] client/rpc: fix panic in sendAcceptBatch In this commit, we fix a panic in `sendAcceptBatch` due to the fact that the method as is, creates a slice with enough _capacity_ but a zero length. In this case, trying to access an index will result in a panic. In this commit, we shift things over to use append instead of index into the slice. --- rpcserver.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/rpcserver.go b/rpcserver.go index 6e2d40c..abb1043 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -1044,10 +1044,8 @@ func (s *rpcServer) sendAcceptBatch(batch *order.Batch) error { // Prepare the list of nonces we accept by serializing them to a slice // of byte slices. nonces := make([][]byte, 0, len(batch.MatchedOrders)) - idx := 0 for nonce := range batch.MatchedOrders { - nonces[idx] = nonce[:] - idx++ + nonces = append(nonces, nonce[:]) } // Send the message to the server.