-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cleanup/improve safety: remove goto and potentially unbounded for loop #120
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -193,14 +193,15 @@ func draw(mat qrcode.Matrix, opt *outputImageOptions) image.Image { | |
if !validLogoImage(w, h, logoWidth, logoHeight, opt.logoSizeMultiplier) { | ||
log.Printf("w=%d, h=%d, logoW=%d, logoH=%d, logo is over than 1/%d of QRCode \n", | ||
w, h, logoWidth, logoHeight, opt.logoSizeMultiplier) | ||
goto done | ||
|
||
return dc.Image() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I couldn't agree that goto is unsafe here, replacing goto by directly return is not necessary There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It’s one less goto to have to check for security issues. Usually they are dangerous during for loops as you can easily end up with unbounded loops or other issues especially if you aren’t fuzzing. In this case it’s simple but I think just adding the return here or switching this to an if else on the ‘dc.DrawImage’ is an easy way to avoid it and thus make security reviews for new users have less red flags to check. |
||
} | ||
|
||
// DONE(@yeqown): calculate the xOffset and yOffset which point(xOffset, yOffset) | ||
// should icon upper-left to start | ||
dc.DrawImage(opt.logoImage(), (w-logoWidth)/2, (h-logoHeight)/2) | ||
} | ||
done: | ||
|
||
return dc.Image() | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any meaning of converting a byte to a rune? raw is a byte slice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Characters are runes in go. Using rune instead of byte encourages comparing to a single character which is the point of these functions since they aren’t Unicode aware.