New Defects reported by Coverity Scan for ntpsec

Gary E. Miller gem at rellim.com
Mon Feb 6 01:53:03 UTC 2023


Yo Hal!

On Sun, 05 Feb 2023 17:38:49 -0800
Hal Murray via devel <devel at ntpsec.org> wrote:

> 1439             default: {
> 1440     	    /* There should be a way for the compiler to
> check this. */ 1441                 bool once =3D false;
> >>>     CID 435753:  Possible Control flow issues  (DEADCODE)
> >>>     Execution cannot reach this statement: "return;". =20  
> 1442                 if (once) return;		/* Avoid log
> file DDoS */
> 
> That's some of my new code.

I figured, since a new coverity issue.
 
> In this case, I'm switching on a enum and have handled all the cases
> so the default "can't happen".

Sadly some compilers will always complain if there is no default.  So
I always add a default.

> How do I get the compiler to tell me if I missed an option on a
> switch statement?

From "man gcc":

       -Wswitch
           Warn whenever a "switch" statement has an index of enumerated type
           and lacks a "case" for one or more of the named codes of that
           enumeration. 

Or the similar -Wswitch-enum

> Of course, the data might get mashed, so the other question is:
>   How do I get coverty to not complain about this code?

// coverity[var_deref_model]

That will ignore a var_deref_model message on the net line.

Grep the ntpsec sources, it is used a lot.  Maybe over used.

RGDS
GARY
---------------------------------------------------------------------------
Gary E. Miller Rellim 109 NW Wilmington Ave., Suite E, Bend, OR 97703
	gem at rellim.com  Tel:+1 541 382 8588

	    Veritas liberabit vos. -- Quid est veritas?
    "If you can't measure it, you can't improve it." - Lord Kelvin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 851 bytes
Desc: OpenPGP digital signature
URL: <https://lists.ntpsec.org/pipermail/devel/attachments/20230205/5c2b6237/attachment.bin>


More information about the devel mailing list