FAQ
I have such function:

func xor(t1, t2 []byte) []byte {
var twoMessage []byte
if len(t1) > len(t2) {
for i, _ := range t2 {
twoMessage[i] = t1[i]^t2[i] // <---- error points to this line
}
} else {
for i, _ := range t1 {
twoMessage[i] = t1[i]^t2[i]
}
}
return twoMessage
}

///-------

xored := xor(hex1, hex2) // <-- error also points this line

but when I try to run program with this message it throws:
panic: runtime error: index out of range

--
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/groups/opt_out.

Search Discussions

  • Egon at Jan 11, 2014 at 11:00 am
    twoMessage isn't being initialized with a length, so len(twoMessage) = 0,
    hence the assignment panics.
    On Saturday, January 11, 2014 12:57:52 PM UTC+2, Dariusz wrote:

    I have such function:

    func xor(t1, t2 []byte) []byte {
    var twoMessage []byte
    if len(t1) > len(t2) {
    for i, _ := range t2 {
    twoMessage[i] = t1[i]^t2[i] // <---- error points to this line
    }
    } else {
    for i, _ := range t1 {
    twoMessage[i] = t1[i]^t2[i]
    }
    }
    return twoMessage
    }

    ///-------

    xored := xor(hex1, hex2) // <-- error also points this line

    but when I try to run program with this message it throws:
    panic: runtime error: index out of range
    --
    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/groups/opt_out.
  • Dariusz at Jan 11, 2014 at 11:18 am
    Thank you! I've fix it and gave them a ficed size. I thought that slices
    work in different way, so looks like I understood them wrong.
    On Saturday, January 11, 2014 12:00:34 PM UTC+1, egon wrote:

    twoMessage isn't being initialized with a length, so len(twoMessage) = 0,
    hence the assignment panics.
    On Saturday, January 11, 2014 12:57:52 PM UTC+2, Dariusz wrote:

    I have such function:

    func xor(t1, t2 []byte) []byte {
    var twoMessage []byte
    if len(t1) > len(t2) {
    for i, _ := range t2 {
    twoMessage[i] = t1[i]^t2[i] // <---- error points to this line
    }
    } else {
    for i, _ := range t1 {
    twoMessage[i] = t1[i]^t2[i]
    }
    }
    return twoMessage
    }

    ///-------

    xored := xor(hex1, hex2) // <-- error also points this line

    but when I try to run program with this message it throws:
    panic: runtime error: index out of range
    --
    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/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJan 11, '14 at 10:57a
activeJan 11, '14 at 11:18a
posts3
users2
websitegolang.org

2 users in discussion

Dariusz: 2 posts Egon: 1 post

People

Translate

site design / logo © 2022 Grokbase