internal/impl: fix off-by-one error in message initialization

This particular off-by-one can never happen in practice. We will crash
if a field has a number one greater than the maximum field number in the
dense array, but if field number N is in the array we will always put
N+1 in it as well.

Fix the off-by-one anyway.

Change-Id: I8c1304f2fc0d7b91036bde3f7ddb7115c21781ca
Reviewed-by: Joe Tsai <>
diff --git a/internal/impl/codec_message.go b/internal/impl/codec_message.go
index 03b096e..5259f2f 100644
--- a/internal/impl/codec_message.go
+++ b/internal/impl/codec_message.go
@@ -136,7 +136,7 @@
 	mi.denseCoderFields = make([]*coderFieldInfo, maxDense+1)
 	for _, cf := range mi.orderedCoderFields {
-		if int(cf.num) > len(mi.denseCoderFields) {
+		if int(cf.num) >= len(mi.denseCoderFields) {
 		mi.denseCoderFields[cf.num] = cf