Skip to content

redis-cli: Assert > 0 before dividing, to silence warning by tool#9396

Merged
oranagra merged 1 commit intoredis:unstablefrom
zuiderkwast:issue9383-division-by-zero-warning
Aug 22, 2021
Merged

redis-cli: Assert > 0 before dividing, to silence warning by tool#9396
oranagra merged 1 commit intoredis:unstablefrom
zuiderkwast:issue9383-division-by-zero-warning

Conversation

@zuiderkwast
Copy link
Contributor

Also make sure function can't return NULL by another assert.

Fixes #9383.

Also make sure function can't return NULL by another assert.
@oranagra
Copy link
Member

so replacing a division by 0 with an assertion? what's the difference? (SIGFPE vs SIGABRT?)

i did do a similar thing in redis recently, and my aim was for the tests to be able to easily distinguish between a crash by signal, and an assertion (also added use-exit-on-panic config to silence valgrind warnings).

my point is, if this is a completely dead code, why bother?
if it's not dead, we may wanna kill it (add a check earlier with a proper error message).
or we can also say we don't care much claiming that it's an invalid use of the tool (a cli tool, not redis server).

@zuiderkwast
Copy link
Contributor Author

It can't happen and an assert is just a way to make that more clear in the code. If the function starts to be used in another place, maybe it can happen. @oranagra if you think it's useless, feel free to close the PR and the issue. :-)

If the warning is from an analysis tool we want to use, we'd want to silence the false warnings. Some tools out there are quite good, but I don't know which one this was. @yiyuaner which tool was it?

@yiyuaner
Copy link
Contributor

yiyuaner commented Aug 21, 2021

It can't happen and an assert is just a way to make that more clear in the code. If the function starts to be used in another place, maybe it can happen. @oranagra if you think it's useless, feel free to close the PR and the issue. :-)

If the warning is from an analysis tool we want to use, we'd want to silence the false warnings. Some tools out there are quite good, but I don't know which one this was. @yiyuaner which tool was it?

It's from an ongoing research project. I don't know the coding practice of redis, but maybe this warning reveals at least dead code (if not potential bugs). Maybe an explicit assert(false) can help to clarify the intention of the programmer. Also, in this case it can also help to suppress the warning from the static analyzer.

Copy link
Member

@oranagra oranagra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, i'll take it.
i.e. i'll consider it a clarification in the code, not a fix..

@oranagra oranagra merged commit 74590f8 into redis:unstable Aug 22, 2021
@oranagra
Copy link
Member

i only not notice the title of the PR (i think i didn't noticed before that it mentions the reason is to silence a warning)
thank you.

JackieXie168 pushed a commit to JackieXie168/redis that referenced this pull request Sep 8, 2021
…dis#9396)

Also make sure function can't return NULL by another assert.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] A possible divide by zero bug in redis-cli.c

3 participants