From 8b1271e880cb66f992a2647ff7940d4dc5a41fee Mon Sep 17 00:00:00 2001 From: Florian Sundermann Date: Wed, 12 Oct 2016 09:13:12 +0200 Subject: [PATCH] fixed datarace --- qr/errorcorrection.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/qr/errorcorrection.go b/qr/errorcorrection.go index eaf5944..950fa82 100644 --- a/qr/errorcorrection.go +++ b/qr/errorcorrection.go @@ -2,10 +2,13 @@ package qr import ( "github.com/boombuler/barcode/utils" + "sync" ) type errorCorrection struct { - fld *utils.GaloisField + fld *utils.GaloisField + + m *sync.Mutex polynomes []*utils.GFPoly } @@ -15,6 +18,7 @@ func newGF() *errorCorrection { fld := utils.NewGaloisField(285) return &errorCorrection{fld, + new(sync.Mutex), []*utils.GFPoly{ utils.NewGFPoly(fld, []byte{1}), }, @@ -22,6 +26,9 @@ func newGF() *errorCorrection { } func (ec *errorCorrection) getPolynomial(degree int) *utils.GFPoly { + ec.m.Lock() + defer ec.m.Unlock() + if degree >= len(ec.polynomes) { last := ec.polynomes[len(ec.polynomes)-1] for d := len(ec.polynomes); d <= degree; d++ {