Browse Source

Fix some warnings

IZI 4 years ago
parent
commit
c780f77ddb
6 changed files with 22 additions and 26 deletions
  1. 4 1
      src/CivetServer.cpp
  2. 3 3
      src/civetweb.c
  3. 5 17
      src/mod_http2.inl
  4. 1 1
      src/mod_lua.inl
  5. 7 3
      src/mod_zlib.inl
  6. 2 1
      src/response.inl

+ 4 - 1
src/CivetServer.cpp

@@ -396,6 +396,7 @@ CivetServer::CivetServer(const char **options,
     : context(0)
 {
 	struct CivetCallbacks callbacks;
+	memset(&callbacks, 0, sizeof(callbacks));
 
 	UserContext = UserContextIn;
 
@@ -407,9 +408,10 @@ CivetServer::CivetServer(const char **options,
 	}
 	callbacks.connection_close = closeHandler;
 	context = mg_start(&callbacks, this, options);
-	if (context == NULL)
+	if (context == NULL) {
 		throw CivetException("null context when constructing CivetServer. "
 		                     "Possible problem binding to port.");
+	}
 }
 
 CivetServer::CivetServer(const std::vector<std::string> &options,
@@ -418,6 +420,7 @@ CivetServer::CivetServer(const std::vector<std::string> &options,
     : context(0)
 {
 	struct CivetCallbacks callbacks;
+	memset(&callbacks, 0, sizeof(callbacks));
 
 	UserContext = UserContextIn;
 

+ 3 - 3
src/civetweb.c

@@ -6344,7 +6344,7 @@ pull_inner(FILE *fp,
 			                  (int)(timeout * 1000.0),
 			                  &(conn->phys_ctx->stop_flag));
 
-			if (conn->phys_ctx->stop_flag) {
+			if (!STOP_FLAG_IS_ZERO(&conn->phys_ctx->stop_flag)) {
 				return -2;
 			}
 		}
@@ -12787,8 +12787,8 @@ mg_websocket_write_exec(struct mg_connection *conn,
 	(void)mg_lock_connection(conn);
 
 #if defined(USE_ZLIB) && defined(MG_EXPERIMENTAL_INTERFACES)
-	size_t deflated_size;
-	Bytef *deflated;
+	size_t deflated_size = 0;
+	Bytef *deflated = 0;
 	// Deflate websocket messages over 100kb
 	int use_deflate = dataLen > 100 * 1024 && conn->accept_gzip;
 

+ 5 - 17
src/mod_http2.inl

@@ -673,7 +673,7 @@ hpack_decode(const uint8_t *buf, int *i, struct mg_context *ctx)
 	/* Now read the string */
 	if (!is_huff) {
 		/* Not huffman encoded: Copy directly */
-		char *result = mg_malloc_ctx(byte_len + 1, ctx);
+		char *result = (char *)mg_malloc_ctx(byte_len + 1, ctx);
 		if (result) {
 			memcpy(result, buf + (*i), byte_len);
 			result[byte_len] = 0;
@@ -1156,25 +1156,13 @@ http2_must_use_http1(struct mg_connection *conn)
 static int mem_h_count = 0;
 static int mem_d_count = 0;
 #define CHECK_LEAK_HDR_ALLOC(ptr)                                              \
-	DEBUG_TRACE("H NEW %08x (%i): %s",                                         \
-	            (uint32_t)ptr,                                                 \
-	            ++mem_h_count,                                                 \
-	            (const char *)ptr)
+	DEBUG_TRACE("H NEW %p (%i): %s", ptr, ++mem_h_count, (const char *)ptr)
 #define CHECK_LEAK_HDR_FREE(ptr)                                               \
-	DEBUG_TRACE("H DEL %08x (%i): %s",                                         \
-	            (uint32_t)ptr,                                                 \
-	            --mem_h_count,                                                 \
-	            (const char *)ptr)
+	DEBUG_TRACE("H DEL %p (%i): %s", ptr, --mem_h_count, (const char *)ptr)
 #define CHECK_LEAK_DYN_ALLOC(ptr)                                              \
-	DEBUG_TRACE("D NEW %08x (%i): %s",                                         \
-	            (uint32_t)ptr,                                                 \
-	            ++mem_d_count,                                                 \
-	            (const char *)ptr)
+	DEBUG_TRACE("D NEW %p (%i): %s", ptr, ++mem_d_count, (const char *)ptr)
 #define CHECK_LEAK_DYN_FREE(ptr)                                               \
-	DEBUG_TRACE("D DEL %08x (%i): %s",                                         \
-	            (uint32_t)ptr,                                                 \
-	            --mem_d_count,                                                 \
-	            (const char *)ptr)
+	DEBUG_TRACE("D DEL %p (%i): %s", ptr, --mem_d_count, (const char *)ptr)
 #else
 #define CHECK_LEAK_HDR_ALLOC(ptr)
 #define CHECK_LEAK_HDR_FREE(ptr)

+ 1 - 1
src/mod_lua.inl

@@ -1240,7 +1240,7 @@ lsp_split_form_urlencoded(lua_State *L)
 	in = lua_tolstring(L, 1, &len);
 
 	/* Create a modifyable copy */
-	buf = mg_malloc_ctx(len + 1, ctx);
+	buf = (char *)mg_malloc_ctx(len + 1, ctx);
 	if (buf == NULL) {
 		return luaL_error(L, "out of memory in invalid split_form_data() call");
 	}

+ 7 - 3
src/mod_zlib.inl

@@ -12,6 +12,7 @@ zalloc(void *opaque, uInt items, uInt size)
 {
 	struct mg_connection *conn = (struct mg_connection *)opaque;
 	void *ret = mg_calloc_ctx(items, size, conn->phys_ctx);
+	(void)conn; /* mg_calloc_ctx makro might not need it */
 
 	return ret;
 }
@@ -125,8 +126,9 @@ send_compressed_data(struct mg_connection *conn, struct mg_file *filep)
 	mg_write(conn, "0\r\n\r\n", 5);
 }
 
+
 #if defined(USE_WEBSOCKET) && defined(MG_EXPERIMENTAL_INTERFACES)
-int
+static int
 websocket_deflate_initialize(struct mg_connection *conn, int server)
 {
 	int zret =
@@ -173,7 +175,8 @@ websocket_deflate_initialize(struct mg_connection *conn, int server)
 	return Z_OK;
 }
 
-void
+
+static void
 websocket_deflate_negotiate(struct mg_connection *conn)
 {
 	const char *extensions = mg_get_header(conn, "Sec-WebSocket-Extensions");
@@ -255,7 +258,8 @@ websocket_deflate_negotiate(struct mg_connection *conn)
 	conn->websocket_deflate_initialized = 0;
 }
 
-void
+
+static void
 websocket_deflate_response(struct mg_connection *conn)
 {
 	if (conn->accept_gzip) {

+ 2 - 1
src/response.inl

@@ -151,7 +151,8 @@ mg_response_header_add(struct mg_connection *conn,
 	conn->response_info.http_headers[hidx].name =
 	    mg_strdup_ctx(header, conn->phys_ctx);
 	if (value_len >= 0) {
-		char *hbuf = mg_malloc_ctx((unsigned)value_len + 1, conn->phys_ctx);
+		char *hbuf =
+		    (char *)mg_malloc_ctx((unsigned)value_len + 1, conn->phys_ctx);
 		if (hbuf) {
 			memcpy(hbuf, value, (unsigned)value_len);
 			hbuf[value_len] = 0;