git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/4] curl_trace(): eliminate switch fallthrough

From
Jeff King <peff@peff.net>
Date
Sep 21, 2017, 06:23 UTC
Message-ID
<20170921062324.ehlfvyng7e62eoti@sigill.intra.peff.net>
In-Reply-To
<20170921062043.la2f3pjsnojirzyw@sigill.intra.peff.net>

Our trace handler is called by curl with a curl_infotype variable to interpret its data field. For most types we print the data and then break out of the switch. But for CURLINFO_TEXT, we print data and then fall through to the "default" case, which does the exact same thing (nothing!) that breaking out of the switch would.

This is probably a leftover from an early iteration of the patch where the code after the switch _did_ do something interesting that was unique to the non-text case arms. But in its current form, this fallthrough is merely confusing (and causes gcc's -Wimplicit-fallthrough to complain).

Let's make CURLINFO_TEXT like the other case arms, and push the default arm to the end where it's more obviously a catch-all.

Signed-off-by: Jeff King <peff@peff.net>
---
 http.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/http.c b/http.c
index 9e40a465fd..713525f38e 100644
--- a/http.c
+++ b/http.c
@@ -638,9 +638,7 @@ static int curl_trace(CURL *handle, curl_infotype type, char *data, size_t size,
 	switch (type) {
 	case CURLINFO_TEXT:
 		trace_printf_key(&trace_curl, "== Info: %s", data);
-	default:		/* we ignore unknown types by default */
-		return 0;
-
+		break;
 	case CURLINFO_HEADER_OUT:
 		text = "=> Send header";
 		curl_dump_header(text, (unsigned char *)data, size, DO_FILTER);
@@ -665,6 +663,9 @@ static int curl_trace(CURL *handle, curl_infotype type, char *data, size_t size,
 		text = "<= Recv SSL data";
 		curl_dump_data(text, (unsigned char *)data, size);
 		break;
+
+	default:		/* we ignore unknown types by default */
+		return 0;
 	}
 	return 0;
 }
-- 
2.14.1.1051.g8c9143ec35
Previous: Junio C HamanoNext: Jeff King
Message 6 of 7 in “appeasing -Wimplicit-fallthrough”
  1. 0/4 appeasing -Wimplicit-fallthroughJeff King, Sep 21, 2017
  2. 1/4 cat-file: handle NULL object_context.pathJeff King, Sep 21, 2017
  3. Jonathan NiederSep 22, 2017
  4. 2/4 test-line-buffer: simplify command parsingJeff King, Sep 21, 2017
  5. Junio C HamanoSep 22, 2017
  6. 3/4 curl_trace(): eliminate switch fallthroughJeff King, Sep 21, 2017
  7. 4/4 consistently use "fallthrough" comments in switchesJeff King, Sep 21, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.