|
@@ -253,20 +253,20 @@ func (r *Rudp) Input(bts []byte) {
|
253
|
253
|
r.lastRecvTick = r.currentTick
|
254
|
254
|
}
|
255
|
255
|
for sz > 0 {
|
256
|
|
- len := int(bts[0])
|
257
|
|
- if len > 127 {
|
|
256
|
+ length := int(bts[0])
|
|
257
|
+ if length > 127 {
|
258
|
258
|
if sz <= 1 {
|
259
|
259
|
r.corrupt.Store(ERROR_MSG_SIZE)
|
260
|
260
|
return
|
261
|
261
|
}
|
262
|
|
- len = (len*256 + int(bts[1])) & 0x7fff
|
|
262
|
+ length = (length*256 + int(bts[1])) & 0x7fff
|
263
|
263
|
bts = bts[2:]
|
264
|
264
|
sz -= 2
|
265
|
265
|
} else {
|
266
|
266
|
bts = bts[1:]
|
267
|
267
|
sz -= 1
|
268
|
268
|
}
|
269
|
|
- switch len {
|
|
269
|
+ switch length {
|
270
|
270
|
case TYPE_PING:
|
271
|
271
|
r.checkMissing(false)
|
272
|
272
|
case TYPE_EOF:
|
|
@@ -281,22 +281,27 @@ func (r *Rudp) Input(bts []byte) {
|
281
|
281
|
}
|
282
|
282
|
exe := r.addRequest
|
283
|
283
|
max := r.sendID
|
284
|
|
- if len == TYPE_MISSING {
|
|
284
|
+ if length == TYPE_MISSING {
|
285
|
285
|
exe = r.addMissing
|
286
|
286
|
max = r.recvIDMax
|
287
|
287
|
}
|
|
288
|
+ // this eliminates multiple BCs in the exe function invocation
|
|
289
|
+ _ = bts[3]
|
288
|
290
|
exe(r.getID(max, bts[0], bts[1]), r.getID(max, bts[2], bts[3]))
|
289
|
291
|
bts = bts[4:]
|
290
|
292
|
sz -= 4
|
291
|
293
|
default:
|
292
|
|
- len -= TYPE_NORMAL
|
293
|
|
- if sz < len+2 {
|
|
294
|
+ length -= TYPE_NORMAL
|
|
295
|
+ if sz < length+2 {
|
294
|
296
|
r.corrupt.Store(ERROR_MSG_SIZE)
|
295
|
297
|
return
|
296
|
298
|
}
|
297
|
|
- r.insertMessage(r.getID(r.recvIDMax, bts[0], bts[1]), bts[2:len+2])
|
298
|
|
- bts = bts[len+2:]
|
299
|
|
- sz -= len + 2
|
|
299
|
+ // this prevents most of the bounds checks in the following code and
|
|
300
|
+ // would fail in the next function call anyway if this is outside
|
|
301
|
+ _ = bts[4]
|
|
302
|
+ r.insertMessage(r.getID(r.recvIDMax, bts[0], bts[1]), bts[2:length+2])
|
|
303
|
+ bts = bts[length+2:]
|
|
304
|
+ sz -= length + 2
|
300
|
305
|
}
|
301
|
306
|
}
|
302
|
307
|
r.checkMissing(false)
|