From d372fa1fa46ae3dc0f9541a509a4875c6efa74a3 Mon Sep 17 00:00:00 2001 From: Marcel Battista Date: Tue, 19 Oct 2021 13:10:43 +0200 Subject: [PATCH] fix panic on single digit throttles values --- src/croc/croc.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/croc/croc.go b/src/croc/croc.go index 4414eb1a..636d54f1 100644 --- a/src/croc/croc.go +++ b/src/croc/croc.go @@ -178,7 +178,8 @@ func New(ops Options) (c *Client, err error) { c.conn = make([]*comm.Comm, 16) - if len(c.Options.ThrottleUpload) > 0 && c.Options.IsSender { + // initialize throttler + if len(c.Options.ThrottleUpload) > 1 && c.Options.IsSender { upload := c.Options.ThrottleUpload[:len(c.Options.ThrottleUpload)-1] uploadLimit, err := strconv.ParseInt(upload, 10, 64) if err != nil { @@ -193,6 +194,11 @@ func New(ops Options) (c *Client, err error) { uploadLimit = uploadLimit*1024*1024 case "k", "K": uploadLimit = uploadLimit*1024 + default: + uploadLimit, err = strconv.ParseInt(c.Options.ThrottleUpload, 10, 64) + if err != nil { + panic("Could not parse given Upload Limit") + } } // Somehow 4* is neccessary rt = rate.Every(time.Second / (4*time.Duration(uploadLimit)))