qrcode: Handle Python3 integer promotion

In Python3, all division operators promote integers to floats.  We need
to downcast back to integer for the polygon vertices.

There was also an unhandled overflow in the QR generation that allowed
more than 512 bits to be loaded.  This overflows the type of QR we
generate, so this truncates the input string to 62 bytes ( leaving 12
bits for the checksum )

Fixes: lp:1850223
* https://bugs.launchpad.net/kicad/+bug/1850223
This commit is contained in:
Seth Hillbrand 2019-11-01 06:30:06 -07:00
parent 65bf669387
commit 9bccbaf497
1 changed files with 3 additions and 2 deletions

View File

@ -42,7 +42,8 @@ class QRCodeWizard(FootprintWizardBase.FootprintWizard):
def CheckParameters(self):
self.Barcode = str(self.parameters['Barcode']['Contents'])
# 512 bits maximum in this type of QR code with 2 bytes reserved
self.Barcode = str(self.parameters['Barcode']['Contents'])[:61]
self.X = self.parameters['Barcode']['Qr Pixel Width']
self.negative = self.parameters['Barcode']['Negative']
self.UseSilkS = self.parameters['Barcode']['Use SilkS layer']
@ -70,7 +71,7 @@ class QRCodeWizard(FootprintWizardBase.FootprintWizard):
polygon.SetShape(pcbnew.S_POLYGON)
polygon.SetWidth( 0 )
polygon.SetLayer(layer)
halfsize = size/2
halfsize = int(size/2)
polygon.GetPolyShape().NewOutline();
polygon.GetPolyShape().Append( halfsize+xposition, halfsize+yposition )
polygon.GetPolyShape().Append( halfsize+xposition, -halfsize+yposition )