]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Fix a compilation warning in networkstatus.c
authorNick Mathewson <nickm@torproject.org>
Wed, 19 Mar 2025 17:39:54 +0000 (13:39 -0400)
committerNick Mathewson <nickm@torproject.org>
Wed, 19 Mar 2025 17:39:54 +0000 (13:39 -0400)
I have no idea why this just showed up for me.
I guess it has something to do with GCC, but I'm not sure.

Closes #41032.

changes/bug41032 [new file with mode: 0644]
src/feature/nodelist/networkstatus.c

diff --git a/changes/bug41032 b/changes/bug41032
new file mode 100644 (file)
index 0000000..25c337c
--- /dev/null
@@ -0,0 +1,2 @@
+  o Minor features (compilation):
+    - Fix a warning when compiling with GCC 14.2.  Closes 41032.
index 61eef5bfa52e9591b9b6ee76eff6ca03360d8865..240756acb6752de9dc546631adff24a55b5fcd71 100644 (file)
@@ -1954,7 +1954,7 @@ networkstatus_set_current_consensus(const char *consensus,
   int free_consensus = 1; /* Free 'c' at the end of the function */
   int checked_protocols_already = 0;
 
-  if (flav < 0) {
+  if (flav < 0 || flav >= N_CONSENSUS_FLAVORS) {
     /* XXXX we don't handle unrecognized flavors yet. */
     log_warn(LD_BUG, "Unrecognized consensus flavor %s", flavor);
     return -2;
@@ -1982,6 +1982,7 @@ networkstatus_set_current_consensus(const char *consensus,
 
   if ((int)c->flavor != flav) {
     /* This wasn't the flavor we thought we were getting. */
+    tor_assert(c->flavor < N_CONSENSUS_FLAVORS);
     if (require_flavor) {
       log_warn(LD_DIR, "Got consensus with unexpected flavor %s (wanted %s)",
                networkstatus_get_flavor_name(c->flavor), flavor);