瀏覽代碼

Fix some warnings and some missing #ifdef after merge

bel2125 7 年之前
父節點
當前提交
021ad9d383
共有 2 個文件被更改,包括 37 次插入11 次删除
  1. 29 2
      src/civetweb.c
  2. 8 9
      src/main.c

+ 29 - 2
src/civetweb.c

@@ -9205,10 +9205,13 @@ mg_send_mime_file2(struct mg_connection *conn,
 	}
 
 	if (mg_stat(conn, path, &file.stat)) {
+#if !defined(NO_CACHING)
 		if (is_not_modified(conn, &file.stat)) {
 			/* Send 304 "Not Modified" - this must not send any body data */
 			handle_not_modified_static_file_request(conn, &file);
-		} else if (file.stat.is_directory) {
+		} else
+#endif /* NO_CACHING */
+		    if (file.stat.is_directory) {
 			if (!mg_strcasecmp(conn->dom_ctx->config[ENABLE_DIRECTORY_LISTING],
 			                   "yes")) {
 				handle_directory_request(conn, path);
@@ -14436,13 +14439,26 @@ ssl_servername_callback(SSL *ssl, int *ad, void *arg)
 	struct mg_context *ctx = (struct mg_context *)arg;
 	struct mg_domain_context *dom =
 	    (struct mg_domain_context *)ctx ? &(ctx->dd) : NULL;
+
+#if defined(__GNUC__) || defined(__MINGW32__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wcast-align"
+#endif /* defined(__GNUC__) || defined(__MINGW32__) */
+
+	/* We used an aligned pointer in SSL_set_app_data */
 	struct mg_connection *conn = (struct mg_connection *)SSL_get_app_data(ssl);
+
+#if defined(__GNUC__) || defined(__MINGW32__)
+#pragma GCC diagnostic pop
+#endif /* defined(__GNUC__) || defined(__MINGW32__) */
+
 	const char *servername = SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name);
 
 	(void)ad;
 
 	if (conn->phys_ctx != ctx) {
-		printf("???\n"); /* XXX */
+		/* Cannot happen - TODO(low): ASSERT ? */
+		DEBUG_TRACE("Internal error: %p != %p", conn->phys_ctx, ctx);
 	}
 
 	/* Old clients (Win XP) will not support SNI. Then, there
@@ -15206,7 +15222,18 @@ mg_connect_client_impl(const struct mg_client_options *client_options,
 		return NULL;
 	}
 
+#if defined(__GNUC__) || defined(__MINGW32__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wcast-align"
+#endif /* defined(__GNUC__) || defined(__MINGW32__) */
+	/* conn_size is aligned to 8 bytes */
+
 	conn->phys_ctx = (struct mg_context *)(((char *)conn) + conn_size);
+
+#if defined(__GNUC__) || defined(__MINGW32__)
+#pragma GCC diagnostic pop
+#endif /* defined(__GNUC__) || defined(__MINGW32__) */
+
 	conn->buf = (((char *)conn) + conn_size + ctx_size);
 	conn->buf_size = (int)max_req_size;
 	conn->phys_ctx->context_type = CONTEXT_HTTP_CLIENT;

+ 8 - 9
src/main.c

@@ -561,10 +561,9 @@ set_option(char **options, const char *name, const char *value)
 		}
 		if (!strcmp(name, main_config_options[OPTION_ADD_DOMAIN].name)) {
 			if (g_num_add_domains > 0) {
-				g_add_domain =
-				    (const char **)realloc((void *)g_add_domain,
-				                           sizeof(char *)
-				                               * (g_num_add_domains + 1));
+				g_add_domain = (const char **)realloc(
+				    (void *)g_add_domain,
+				    sizeof(char *) * ((unsigned)g_num_add_domains + 1u));
 				if (!g_add_domain) {
 					die("Out of memory");
 				}
@@ -856,7 +855,7 @@ init_system_info(void)
 
 
 static void
-init_server_name()
+init_server_name(void)
 {
 	assert(sizeof(main_config_options) / sizeof(main_config_options[0])
 	       == NUM_MAIN_OPTIONS + 1);
@@ -1146,7 +1145,7 @@ run_client(const char *url_arg)
 			/* Respond reader read. Read body (if any) */
 			ret = mg_read(conn, buf, sizeof(buf));
 			while (ret > 0) {
-				fwrite(buf, 1, ret, stdout);
+				fwrite(buf, 1, (unsigned)ret, stdout);
 				ret = mg_read(conn, buf, sizeof(buf));
 			}
 
@@ -2889,7 +2888,7 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR cmdline, int show)
 	(void)cmdline;
 	(void)show;
 
-	init_server_name((int)__argc, (const char **)__argv);
+	init_server_name();
 	init_system_info();
 	memset(&cls, 0, sizeof(cls));
 	cls.lpfnWndProc = (WNDPROC)WindowProc;
@@ -2992,7 +2991,7 @@ main(int argc, char *argv[])
 int
 main(int argc, char *argv[])
 {
-	init_server_name(argc, (const char **)argv);
+	init_server_name();
 	init_system_info();
 	start_civetweb(argc, argv);
 
@@ -3061,7 +3060,7 @@ main(int argc, char *argv[])
 int
 main(int argc, char *argv[])
 {
-	init_server_name(argc, (const char **)argv);
+	init_server_name();
 	init_system_info();
 	start_civetweb(argc, argv);
 	fprintf(stdout,