url.QueryEscape unexpectedly slow

56 views
Skip to first unread message

Liam

unread,
May 25, 2020, 5:54:57 PM5/25/20
to golang-nuts
I would expect this to complete pretty quickly, but after 40 minutes (on 1.13, linux/amd64), it hasn't printed a thing.

I'm following up a report of panic in QueryEscape: https://github.com/golang/go/issues/38643

package main

import (
   "net/url"
   "fmt"
)

func main() {
   for a := byte(0); a <= 255; a++ {
      if (a+1) % 8 == 0 { fmt.Println(a) }
      for b := byte(0); b <= 255; b++ {
         _ = url.QueryEscape(string([]byte{a,b}))
      }
   }
}

robert engels

unread,
May 25, 2020, 6:54:42 PM5/25/20
to Liam, golang-nuts
This is an infinite loop:

      for b := byte(0); b <= 255; b++ {
         _ = url.QueryEscape(string([]byte{a,b}))
      }

b will always be <= 255 because it is a byte.


Ian Davis

unread,
May 25, 2020, 6:55:15 PM5/25/20
to golan...@googlegroups.com
Don't use a byte for your loops, use an int.

When your loop reaches 255 it is incremented to 0 which is still <= 255 so your loop never terminates.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages