Selaa lähdekoodia

review fixes

1. Avoid undefined behavior of time.Time{}.UnixNano()
2. Times should be compared with Equal()
tags/v2.4.0-rc1
Shivaram Lingamneni 3 vuotta sitten
vanhempi
commit
1ec029a53b
1 muutettua tiedostoa jossa 12 lisäystä ja 5 poistoa
  1. 12
    5
      irc/channelreg.go

+ 12
- 5
irc/channelreg.go Näytä tiedosto

@@ -200,8 +200,11 @@ func (reg *ChannelRegistry) LoadChannel(nameCasefolded string) (info RegisteredC
200 200
 		founder, _ := tx.Get(fmt.Sprintf(keyChannelFounder, channelKey))
201 201
 		topic, _ := tx.Get(fmt.Sprintf(keyChannelTopic, channelKey))
202 202
 		topicSetBy, _ := tx.Get(fmt.Sprintf(keyChannelTopicSetBy, channelKey))
203
-		topicSetTime, _ := tx.Get(fmt.Sprintf(keyChannelTopicSetTime, channelKey))
204
-		topicSetTimeInt, _ := strconv.ParseInt(topicSetTime, 10, 64)
203
+		var topicSetTime time.Time
204
+		topicSetTimeStr, _ := tx.Get(fmt.Sprintf(keyChannelTopicSetTime, channelKey))
205
+		if topicSetTimeInt, topicSetTimeErr := strconv.ParseInt(topicSetTimeStr, 10, 64); topicSetTimeErr == nil {
206
+			topicSetTime = time.Unix(0, topicSetTimeInt).UTC()
207
+		}
205 208
 		password, _ := tx.Get(fmt.Sprintf(keyChannelPassword, channelKey))
206 209
 		modeString, _ := tx.Get(fmt.Sprintf(keyChannelModes, channelKey))
207 210
 		userLimitString, _ := tx.Get(fmt.Sprintf(keyChannelUserLimit, channelKey))
@@ -237,7 +240,7 @@ func (reg *ChannelRegistry) LoadChannel(nameCasefolded string) (info RegisteredC
237 240
 			Founder:        founder,
238 241
 			Topic:          topic,
239 242
 			TopicSetBy:     topicSetBy,
240
-			TopicSetTime:   time.Unix(0, topicSetTimeInt).UTC(),
243
+			TopicSetTime:   topicSetTime,
241 244
 			Key:            password,
242 245
 			Modes:          modeSlice,
243 246
 			Bans:           banlist,
@@ -277,7 +280,7 @@ func (reg *ChannelRegistry) deleteChannel(tx *buntdb.Tx, key string, info Regist
277 280
 		founder, _ := tx.Get(fmt.Sprintf(keyChannelFounder, key))
278 281
 
279 282
 		// to see if we're deleting the right channel, confirm the founder and the registration time
280
-		if founder == info.Founder && registeredAt == info.RegisteredAt {
283
+		if founder == info.Founder && registeredAt.Equal(info.RegisteredAt) {
281 284
 			for _, keyFmt := range channelKeyStrings {
282 285
 				tx.Delete(fmt.Sprintf(keyFmt, key))
283 286
 			}
@@ -345,7 +348,11 @@ func (reg *ChannelRegistry) saveChannel(tx *buntdb.Tx, channelInfo RegisteredCha
345 348
 
346 349
 	if includeFlags&IncludeTopic != 0 {
347 350
 		tx.Set(fmt.Sprintf(keyChannelTopic, channelKey), channelInfo.Topic, nil)
348
-		tx.Set(fmt.Sprintf(keyChannelTopicSetTime, channelKey), strconv.FormatInt(channelInfo.TopicSetTime.UnixNano(), 10), nil)
351
+		var topicSetTimeStr string
352
+		if !channelInfo.TopicSetTime.IsZero() {
353
+			topicSetTimeStr = strconv.FormatInt(channelInfo.TopicSetTime.UnixNano(), 10)
354
+		}
355
+		tx.Set(fmt.Sprintf(keyChannelTopicSetTime, channelKey), topicSetTimeStr, nil)
349 356
 		tx.Set(fmt.Sprintf(keyChannelTopicSetBy, channelKey), channelInfo.TopicSetBy, nil)
350 357
 	}
351 358
 

Loading…
Peruuta
Tallenna