FAQ
Below code generates index out of bound error only when running with a
-race option. It works fine without -race.

package main
import "fmt"
type Session struct {
Username string
}
func main() {
s1 := &Session{"user1"}
s2 := &Session{"user2"}
var sl []*Session
sl = append(sl, s1)
sl = append(sl, s2)

fmt.Println(sl)
sl = deleteSessionSliceItem(sl, s1)
fmt.Println(sl)
}
func deleteSessionSliceItem(sl []*Session, s *Session) []*Session {
if i := getSessionSliceIndex(sl, s); i >= 0 {
sl[i], sl[len(sl)-1], sl = sl[len(sl)-1], nil, sl[:len(sl)-1]
}
return sl
}
func getSessionSliceIndex(sl []*Session, s *Session) int {
for i, item := range sl {
if item == s {
return i
}
}

return -1
}


--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Ian Lance Taylor at Jun 12, 2015 at 9:01 pm

    On Fri, Jun 12, 2015 at 9:56 AM, wrote:
    Below code generates index out of bound error only when running with a -race
    option. It works fine without -race.
    I can recreate the problem with Go 1.4, but fortunately it seems to
    work correctly on tip.

    Ian

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Dipen Bhikadya at Jun 13, 2015 at 11:50 am
    Any idea, when the working version may get released?
    On Saturday, June 13, 2015 at 2:31:21 AM UTC+5:30, Ian Lance Taylor wrote:

    On Fri, Jun 12, 2015 at 9:56 AM, <dipen.b...@gmail.com <javascript:>>
    wrote:
    Below code generates index out of bound error only when running with a -race
    option. It works fine without -race.
    I can recreate the problem with Go 1.4, but fortunately it seems to
    work correctly on tip.

    Ian
    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Dave Cheney at Jun 13, 2015 at 12:12 pm
    Go 1.5 is due to be released in August.

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Dipen Bhikadya at Jun 13, 2015 at 2:04 pm
    Thank you Ian and Dave for your responses.
    On Saturday, June 13, 2015, Dave Cheney wrote:

    Go 1.5 is due to be released in August.

    --
    You received this message because you are subscribed to a topic in the
    Google Groups "golang-nuts" group.
    To unsubscribe from this topic, visit
    https://groups.google.com/d/topic/golang-nuts/3vd3sgcjW2o/unsubscribe.
    To unsubscribe from this group and all its topics, send an email to
    golang-nuts+unsubscribe@googlegroups.com <javascript:;>.
    For more options, visit https://groups.google.com/d/optout.
    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Brad Fitzpatrick at Jun 13, 2015 at 2:57 pm
    Dmitry, do you remember fixing this?

    On Fri, Jun 12, 2015 at 2:01 PM, Ian Lance Taylor wrote:
    On Fri, Jun 12, 2015 at 9:56 AM, wrote:

    Below code generates index out of bound error only when running with a -race
    option. It works fine without -race.
    I can recreate the problem with Go 1.4, but fortunately it seems to
    work correctly on tip.

    Ian

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Dmitry Vyukov at Jun 13, 2015 at 3:24 pm
    Looks like this bug:
    https://github.com/golang/go/issues/9137

    It is not fixed, but probably write barriers "fixed this".


    On Sat, Jun 13, 2015 at 4:57 PM, Brad Fitzpatrick wrote:
    Dmitry, do you remember fixing this?

    On Fri, Jun 12, 2015 at 2:01 PM, Ian Lance Taylor wrote:
    On Fri, Jun 12, 2015 at 9:56 AM, wrote:

    Below code generates index out of bound error only when running with a
    -race
    option. It works fine without -race.
    I can recreate the problem with Go 1.4, but fortunately it seems to
    work correctly on tip.

    Ian

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Peter Kleiweg at Jun 13, 2015 at 3:29 pm
    What is the correct behavior, with or withour -race ?

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJun 12, '15 at 8:27p
activeJun 13, '15 at 3:29p
posts8
users6
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase