-
Notifications
You must be signed in to change notification settings - Fork 276
Attempt to fix CID 530895 #949
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
Open
cmb69
wants to merge
1
commit into
libgd:master
Choose a base branch
from
cmb69:cmb/cid530895
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
we should never use
assert()
in library code that users can get to. would be nice if we could add a CI check to ban it in all library code. tests & examples are fine to use assert/etc... of course.we should return errors back up, and if we think it's helpful (e.g. for bad API calls), log an error via gd_error.
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.
This is in a static function which is only called by the
gdImageCopyGaussianBlurred()
API which alread has:libgd/src/gd_filter.c
Lines 1009 to 1011 in 0b8d708
This
assert()
is only a sanity check that we use the static function properly, and also a hint for static analyzers (and manual code review).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.
the nuance when it's "ok" to use assert and when people are just being lazy is very hard to communicate. people see it being used in some places and think it's ok in general.
since it's a static function, the compiler should inline it. and the compiler should be able to see the higher level has the same check and elide one of them. a quick check over here suggests it does, so the generated code is the same.
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.
For me,
assert()
is a development tool. Release builds should always defineNDEBUG
, so asserts are a no-op (in my opinion, it would be better to have that the other way round: need to defineDEBUG
to enable asserts). We doing this:libgd/src/gd_filter.c
Lines 23 to 28 in 0b8d708
(and yes, I agree that should be moved to configure)
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.
enabling extra debug in a library should not cause it to abort and kill a process. assert usage in programs is different from libraries. we should have no asserts in the gd library regardless of its compilation mode. the existing asserts are "ok" in the sense that they always force NDEBUG which means the calls are empty. interesting that coverity accepts that behavior ... I can see both sides there.