From 608a8ad6112848b23589754e9f32bffc96b09e98 Mon Sep 17 00:00:00 2001 From: huysentruitw Date: Wed, 9 Feb 2022 09:17:15 +0100 Subject: [PATCH] Fix bug in DataMatrix padding algorithm --- datamatrix/encoder.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/datamatrix/encoder.go b/datamatrix/encoder.go index b8921dc..ea852e8 100644 --- a/datamatrix/encoder.go +++ b/datamatrix/encoder.go @@ -69,7 +69,12 @@ func addPadding(data []byte, toCount int) []byte { } for len(data) < toCount { R := ((149 * (len(data) + 1)) % 253) + 1 - data = append(data, byte((129+R)%254)) + tmp := 129 + R; + if (tmp > 254) { + tmp = tmp - 254 + } + + data = append(data, byte(tmp)) } return data }