[Csnd-dev] Coverity question
Date | 2017-11-15 21:04 |
From | jpff |
Subject | [Csnd-dev] Coverity question |
The recent coverity scan threw up again a question I would like resolved. In C the switch/case statements allow fall-trug unless there is an explicit break. This allows easy statements like switch (character) { case '0': case '1': case '2': printf("small\n"); break; default: printf("not small\n"); break; } or even switch (character) { case '3': case '4': printf("not very "); case '0': case '1': case '2': printf("small\n"); default: printf("not small\n"); break; } Coverity flags these as defects wen it is often what I mean. How to I convince the dumb program that it is correct (and there has been no case of a missing break in 25 years)? |
Date | 2017-11-15 21:10 |
From | Victor Lazzarini |
Subject | Re: [Csnd-dev] Coverity question |
Not sure anything is possible beyond marking these as false positives.
Maybe a question for the coverity issue
tracker if there is such a thing.
Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland
|
Date | 2017-11-15 22:12 |
From | Felipe Sateler |
Subject | Re: [Csnd-dev] Coverity question |
You can signal the coverity analizer that the fall through is intended with a comment: switch(num) { case 0: printf("small "); /* fall through */ default: printf("number\n"); } https://www.synopsys.com/blogs/software-security/gimme-a-break/ On Wed, Nov 15, 2017 at 6:10 PM, Victor Lazzarini <Victor.Lazzarini@mu.ie> wrote:
Saludos, Felipe Sateler |