boombuler / barcode

a barcode creation lib for golang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Data race's

RubenN opened this issue · comments

commented

I found three data races while trying to use this component in a go-routine.
They seem to occur because of the unprotected access of maps.

WARNING: DATA RACE
Read at 0x00c0424302b0 by goroutine 23:
  github.com/boombuler/barcode/qr.(*errorCorrection).getPolynomial()
      d:/projects/go/src/github.com/boombuler/barcode/qr/errorcorrection.go:33 +0x474
  github.com/boombuler/barcode/qr.(*errorCorrection).calcECC()
      d:/projects/go/src/github.com/boombuler/barcode/qr/errorcorrection.go:37 +0x6c
  github.com/boombuler/barcode/qr.splitToBlocks()
      d:/projects/go/src/github.com/boombuler/barcode/qr/blocks.go:18 +0x346
  github.com/boombuler/barcode/qr.Encode()
      d:/projects/go/src/github.com/boombuler/barcode/qr/encoder.go:64 +0x106
WARNING: DATA RACE
Read at 0x00c0424302b0 by goroutine 23:
  github.com/boombuler/barcode/qr.(*errorCorrection).getPolynomial()
      d:/projects/go/src/github.com/boombuler/barcode/qr/errorcorrection.go:33 +0x474
  github.com/boombuler/barcode/qr.(*errorCorrection).calcECC()
      d:/projects/go/src/github.com/boombuler/barcode/qr/errorcorrection.go:37 +0x6c
  github.com/boombuler/barcode/qr.splitToBlocks()
      d:/projects/go/src/github.com/boombuler/barcode/qr/blocks.go:18 +0x346
  github.com/boombuler/barcode/qr.Encode()
      d:/projects/go/src/github.com/boombuler/barcode/qr/encoder.go:64 +0x106
WARNING: DATA RACE
Read at 0x00c04229ea00 by goroutine 25:
  github.com/boombuler/barcode/utils.(*GFPoly).MultByMonominal()
      d:/projects/go/src/github.com/boombuler/barcode/utils/gfpoly.go:48 +0xf3
  github.com/boombuler/barcode/utils.(*GFPoly).Divide()
      d:/projects/go/src/github.com/boombuler/barcode/utils/gfpoly.go:81 +0x438
  github.com/boombuler/barcode/qr.(*errorCorrection).calcECC()
      d:/projects/go/src/github.com/boombuler/barcode/qr/errorcorrection.go:41 +0xfa
  github.com/boombuler/barcode/qr.splitToBlocks()
      d:/projects/go/src/github.com/boombuler/barcode/qr/blocks.go:18 +0x346
  github.com/boombuler/barcode/qr.Encode()
      d:/projects/go/src/github.com/boombuler/barcode/qr/encoder.go:64 +0x106

The first 2 dataraces should be fixed (since they are the same).
For the last one I don't see the problem. The slices there are used read-only once they are created so it should not be a problem and protecting them would only make the code a little slower.

Please have a look and correct me if I'm wrong.

commented

Thanks, I have not been able to get another race condition with this fix in place.
All good for now!