فهرست منبع

Supress clang warning for protocol string generation

bel 8 سال پیش
والد
کامیت
60c778ea7a
1فایلهای تغییر یافته به همراه20 افزوده شده و 6 حذف شده
  1. 20 6
      src/civetweb.c

+ 20 - 6
src/civetweb.c

@@ -2880,6 +2880,24 @@ mg_get_request_link(const struct mg_connection *conn, char *buf, size_t buflen)
 		int truncated = 0;
 		int truncated = 0;
 		const struct mg_request_info *ri = &conn->request_info;
 		const struct mg_request_info *ri = &conn->request_info;
 
 
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunreachable-code"
+/* Depending on USE_WEBSOCKET and NO_SSL, some oft the protocols might be
+ * not supported. Clang raises an "unreachable code" warning for parts of ?:
+ * unreachable, but splitting into four different #ifdef clauses here is more
+ * complicated.
+ */
+#endif
+
+		const char *proto =
+		    (is_websocket_protocol(conn) ? (ri->is_ssl ? "wss" : "ws")
+		                                 : (ri->is_ssl ? "https" : "http"));
+
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
+
 		if (ri->local_uri == NULL) {
 		if (ri->local_uri == NULL) {
 			return -1;
 			return -1;
 		}
 		}
@@ -2890,9 +2908,8 @@ mg_get_request_link(const struct mg_connection *conn, char *buf, size_t buflen)
 			            &truncated,
 			            &truncated,
 			            buf,
 			            buf,
 			            buflen,
 			            buflen,
-			            "%s%s://%s",
-			            (is_websocket_protocol(conn) ? "ws" : "http"),
-			            (ri->is_ssl ? "s" : ""),
+			            "%s://%s",
+			            proto,
 			            ri->request_uri);
 			            ri->request_uri);
 			if (truncated) {
 			if (truncated) {
 				return -1;
 				return -1;
@@ -2917,9 +2934,6 @@ mg_get_request_link(const struct mg_connection *conn, char *buf, size_t buflen)
 
 
 			char portstr[16];
 			char portstr[16];
 			char server_ip[48];
 			char server_ip[48];
-			const char *proto =
-			    (is_websocket_protocol(conn) ? (ri->is_ssl ? "wss" : "ws")
-			                                 : (ri->is_ssl ? "https" : "http"));
 
 
 			if (port != def_port) {
 			if (port != def_port) {
 				sprintf(portstr, ":%u", (unsigned)port);
 				sprintf(portstr, ":%u", (unsigned)port);