[Git][NTPsec/ntpsec][master] Add -Wswitch-enum

Hal Murray (@hal.murray) gitlab at mg.gitlab.com
Wed Feb 8 09:47:52 UTC 2023



Hal Murray pushed to branch master at NTPsec / ntpsec


Commits:
60ff0d5b by Hal Murray at 2023-02-07T21:11:44-08:00
Add -Wswitch-enum

There were 2 places in ntp_control where I really wanted this.

It wasn't hard to fix the other warnings this generated.

- - - - -


6 changed files:

- libntp/authkeys.c
- libntp/authreadkeys.c
- ntpd/refclock_gpsd.c
- ntpd/refclock_oncore.c
- ntpd/refclock_truetime.c
- wscript


Changes:

=====================================
libntp/authkeys.c
=====================================
@@ -555,6 +555,7 @@ authencrypt(
 	    case AUTH_CMAC:
 		authcmacencrypt++;
 		return cmac_encrypt(auth, pkt, length);
+	    case AUTH_NONE:
 	    default:
 		msyslog(LOG_ERR, "BUG: authencrypt: bogus type %u", auth->type);
 		exit(1);
@@ -594,6 +595,7 @@ authdecrypt(
 		answer = cmac_decrypt(auth, pkt, length, size);
 		if (!answer) authcmacfail++;
 		return answer;
+	    case AUTH_NONE:
 	    default:
 		msyslog(LOG_ERR, "BUG: authdecrypt: bogus type %u", auth->type);
 		exit(1);


=====================================
libntp/authreadkeys.c
=====================================
@@ -174,6 +174,7 @@ check_mac_length(
 	    case AUTH_DIGEST:
 		check_digest_mac_length(keyno, name);
 		break;
+	    case AUTH_NONE:
 	    default:
 		msyslog(LOG_ERR, "BUG: authreadkeys: unknown AUTH type for key %u, %s", keyno, upcased);
 	}
@@ -224,6 +225,7 @@ check_key_length(
 	    case AUTH_DIGEST:
 		/* any length key works */
 		break;
+	    case AUTH_NONE:
 	    default:
 		msyslog(LOG_ERR, "BUG: authreadkeys: unknown AUTH type for key %u", keyno);
 	}


=====================================
ntpd/refclock_gpsd.c
=====================================
@@ -1172,6 +1172,7 @@ json_token_skip(
 
                 case JSMN_PRIMITIVE:
                 case JSMN_STRING:
+                case JSMN_UNDEFINED:
 		default:
 			++tid;
 			break;


=====================================
ntpd/refclock_oncore.c
=====================================
@@ -2374,6 +2374,7 @@ oncore_msg_BaEaHa(
 		case MODE_0D:	i = 1; break;	/* 0D, Position Hold */
 		case MODE_2D:	i = 2; break;	/* 2D, Altitude Hold */
 		case MODE_3D:	i = 3; break;	/* 3D fix */
+		case MODE_UNKNOWN:
 		default:	i = 0; break;
 		}
 
@@ -3355,6 +3356,7 @@ oncore_antenna_report(
 	case ONCORE_ANTENNA_OC: cp = "GPS antenna: short (overcurrent)";  break;
 	case ONCORE_ANTENNA_UC: cp = "GPS antenna: open (not connected)"; break;
 	case ONCORE_ANTENNA_NV: cp = "GPS antenna: short (no voltage)";   break;
+	case ONCORE_ANTENNA_UNKNOWN:
 	default:		cp = "GPS antenna: ?";                    break;
 	}
 


=====================================
ntpd/refclock_truetime.c
=====================================
@@ -560,6 +560,9 @@ true_doevent(
 			}
 			up->state = s_Auto;
 			break;
+		case e_Huh:
+		case e_Location:
+		case e_Max:
 		default:
 			break;
 		}
@@ -579,6 +582,12 @@ true_doevent(
 			}
 			up->state = s_Auto;
 			break;
+		case e_Huh:
+		case e_F18:
+		case e_F50:
+		case e_F51:
+		case e_Location:
+		case e_Max:
 		default:
 			break;
 		}
@@ -591,6 +600,12 @@ true_doevent(
                     case e_TS:
                         up->state = s_Auto;
                         break;
+                    case e_Huh:
+                    case e_F18:
+                    case e_F50:
+                    case e_F51:
+                    case e_Location:
+                    case e_Max:
                     default:
                         break;
                 }
@@ -610,6 +625,12 @@ true_doevent(
 			case e_Huh:
                                 sleep(1);               /* wait for it */
                                 break;
+			case e_F18:
+			case e_F50:
+			case e_F51:
+			case e_TS:
+			case e_Location:
+			case e_Max:
                         default:
                                 abort();
                         }
@@ -625,6 +646,11 @@ true_doevent(
 				true_send(peer, "PO\r");
 				up->state = s_InqTCU;
 				break;
+			case e_F50:
+			case e_F51:
+			case e_Location:
+			case e_TS:
+			case e_Max:
 			default:
                                 msyslog(LOG_INFO,
                                         "REFCLOCK: TRUETIME: TM/TMD init fellthrough!");
@@ -642,6 +668,11 @@ true_doevent(
 				up->state = s_Base;
 				sleep(1);	/* XXX */
 				break;
+			case e_F18:
+			case e_F50:
+			case e_F51:
+			case e_TS:
+			case e_Max:
 			default:
                                 msyslog(LOG_INFO,
                                         "REFCLOCK: TRUETIME: TCU init fellthrough!");
@@ -665,6 +696,7 @@ true_doevent(
 			break;
 		}
 		break;
+	case t_Max:
 	default:
                 msyslog(LOG_INFO, "REFCLOCK: TRUETIME: cannot identify refclock!");
 		abort();


=====================================
wscript
=====================================
@@ -366,7 +366,9 @@ def configure(ctx):
             # "-Wnested-externs",     # incompatible w/ Unity...
             # "-Wpadded",             # duck... over 3k warnings
             # "-Wredundant-decls",    # incompatible w/ Unity
-            "-Wswitch-default",       # warns on Bison bug
+            "-Wswitch-default",       # warns on missing switch-default
+                                        # old Bison triggers this
+            "-Wswitch-enum",          # warns on missing enum case handler
         ] + ctx.env.CFLAGS
         cc_test_flags += [
             ('w_implicit_fallthru', "-Wimplicit-fallthrough=3"),



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/60ff0d5bc3c161a4510a16cae6d29d21cbbb0f47

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/60ff0d5bc3c161a4510a16cae6d29d21cbbb0f47
You're receiving this email because of your account on gitlab.com.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20230208/107bb025/attachment-0001.htm>


More information about the vc mailing list