Csound Csound-dev Csound-tekno Search About

[Csnd-dev] Coverity question

Date2017-11-15 21:04
Fromjpff
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)?

Date2017-11-15 21:10
FromVictor Lazzarini
SubjectRe: [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

On 15 Nov 2017, at 21:05, jpff <jpff@CODEMIST.CO.UK> wrote:

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)?

==John ffitch

Date2017-11-15 22:12
FromFelipe Sateler
SubjectRe: [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:
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

On 15 Nov 2017, at 21:05, jpff <jpff@CODEMIST.CO.UK> wrote:

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)?

==John ffitch



--

Saludos,
Felipe Sateler