When ranging over an array of structures, the iterand is reused. So storing a
pointer to it will cause trouble down the road.
--- a/roster.go Tue Jan 03 16:56:28 2012 -0700
+++ b/roster.go Thu Jan 05 14:25:40 2012 -0700
@@ -50,8 +50,8 @@
return false
}
cl.roster = make(map[string] *RosterItem, len(rq.Item))
- for _, item := range(rq.Item) {
- cl.roster[item.Jid] = &item
+ for i, item := range(rq.Item) {
+ cl.roster[item.Jid] = &rq.Item[i]
}
ch <- nil
return false
@@ -95,11 +95,11 @@
func (cl *Client) maybeUpdateRoster(st Stanza) {
rq, ok := st.GetNested().(*RosterQuery)
if st.GetName() == "iq" && st.GetType() == "set" && ok {
- for _, item := range(rq.Item) {
+ for i, item := range(rq.Item) {
if item.Subscription == "remove" {
cl.roster[item.Jid] = nil
} else {
- cl.roster[item.Jid] = &item
+ cl.roster[item.Jid] = &rq.Item[i]
}
}
}