Browse Source

Merge remote-tracking branch 'upstream/master'

Eric Tsau 10 years ago
parent
commit
4630ee59df
4 changed files with 136 additions and 79 deletions
  1. 39 8
      examples/embedded_c/embedded_c.c
  2. 45 33
      src/civetweb.c
  3. 45 33
      src/main.c
  4. 7 5
      src/mod_lua.inl

+ 39 - 8
examples/embedded_c/embedded_c.c

@@ -27,12 +27,15 @@ int ExampleHandler(struct mg_connection *conn, void *cbdata)
     mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n");
     mg_printf(conn, "<html><body>");
     mg_printf(conn, "<h2>This is an example text from a C handler</h2>");
-    mg_printf(conn, "<p>To see a page from the A handler <a href=\"A\">click here</a></p>");
-    mg_printf(conn, "<p>To see a page from the A/B handler <a href=\"A/B\">click here</a></p>");
-    mg_printf(conn, "<p>To see a page from the *.foo handler <a href=\"xy.foo\">click here</a></p>");
-    mg_printf(conn, "<p>To test websocket handler <a href=\"/websocket\">click here</a></p>");
-    mg_printf(conn, "<p>To exit <a href=\"%s\">click here</a></p>",
-              EXIT_URI);
+    mg_printf(conn, "<p>To see a page from the A handler <a href=\"A\">click A</a></p>");
+    mg_printf(conn, "<p>To see a page from the A handler <a href=\"A/A\">click A/A</a></p>");
+    mg_printf(conn, "<p>To see a page from the A/B handler <a href=\"A/B\">click A/B</a></p>");
+    mg_printf(conn, "<p>To see a page from the B handler (0) <a href=\"B\">click B</a></p>");
+    mg_printf(conn, "<p>To see a page from the B handler (1) <a href=\"B/A\">click B/A</a></p>");
+    mg_printf(conn, "<p>To see a page from the B handler (2) <a href=\"B/B\">click B/B</a></p>");
+    mg_printf(conn, "<p>To see a page from the *.foo handler <a href=\"xy.foo\">click xy.foo</a></p>");
+    mg_printf(conn, "<p>To test websocket handler <a href=\"/websocket\">click websocket</a></p>");
+    mg_printf(conn, "<p>To exit <a href=\"%s\">click exit</a></p>", EXIT_URI);
     mg_printf(conn, "</body></html>\n");
     return 1;
 }
@@ -67,6 +70,20 @@ int ABHandler(struct mg_connection *conn, void *cbdata)
 }
 
 
+int BXHandler(struct mg_connection *conn, void *cbdata)
+{
+    /* Handler may access the request info using mg_get_request_info */
+    const struct mg_request_info * req_info = mg_get_request_info(conn);
+
+    mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n");
+    mg_printf(conn, "<html><body>");
+    mg_printf(conn, "<h2>This is the BX handler %i!!!</h2>", (int)cbdata);
+    mg_printf(conn, "<p>The actual uri is %s</p>", req_info->uri);
+    mg_printf(conn, "</body></html>\n");
+    return 1;
+}
+
+
 int FooHandler(struct mg_connection *conn, void *cbdata)
 {
     /* Handler may access the request info using mg_get_request_info */
@@ -204,12 +221,26 @@ int main(int argc, char *argv[])
     memset(&callbacks, 0, sizeof(callbacks));
     ctx = mg_start(&callbacks, 0, options);
 
+    /* Handler EXAMPLE_URI to explain the example */
     mg_set_request_handler(ctx, EXAMPLE_URI, ExampleHandler, 0);
     mg_set_request_handler(ctx, EXIT_URI, ExitHandler, 0);
-    mg_set_request_handler(ctx, "/a", AHandler, 0);
-    mg_set_request_handler(ctx, "/a/b", ABHandler, 0);
+
+    /* Handler for /A* and special handler for /A/B */
+    mg_set_request_handler(ctx, "/A", AHandler, 0);
+    mg_set_request_handler(ctx, "/A/B", ABHandler, 0);
+
+    /* Handler for /B, /B/A, /B/B but not for /B* */
+    mg_set_request_handler(ctx, "/B$", BXHandler, (void*)0);
+    mg_set_request_handler(ctx, "/B/A$", BXHandler, (void*)1);
+    mg_set_request_handler(ctx, "/B/B$", BXHandler, (void*)2);
+
+    /* Handler for all files with .foo extention */
     mg_set_request_handler(ctx, "**.foo$", FooHandler, 0);
+
+    /* HTTP site to open a websocket connection */
     mg_set_request_handler(ctx, "/websocket", WebSocketStartHandler, 0);
+
+    /* WS site for the websocket connection */
     mg_set_websocket_handler(ctx, "/websocket", WebSocketConnectHandler, WebSocketReadyHandler, WebsocketDataHandler, WebSocketCloseHandler, 0);
 
     printf("Browse files at http://localhost:%s/\n", PORT);

+ 45 - 33
src/civetweb.c

@@ -208,7 +208,7 @@ mg_static_assert(PATH_MAX >= 1, "path length must be a positive number");
 
 typedef long off_t;
 
-#define errno (GetLastError())
+#define errno ((int)(GetLastError()))
 #define strerror(x) (_ultoa(x, (char *)_alloca(sizeof(x) * 3), 10))
 #endif /* _WIN32_WCE */
 
@@ -236,7 +236,7 @@ typedef long off_t;
 #endif
 #endif /* _MSC_VER */
 
-#define ERRNO (GetLastError())
+#define ERRNO ((int)(GetLastError()))
 #define NO_SOCKLEN_T
 #define SSL_LIB "ssleay32.dll"
 #define CRYPTO_LIB "libeay32.dll"
@@ -457,7 +457,9 @@ static int pthread_setspecific(pthread_key_t key, void *value)
 	return TlsSetValue(key, value) ? 0 : 1;
 }
 
+#ifdef ENABLE_UNUSED_PTHREAD_FUNCTIONS
 static void *pthread_getspecific(pthread_key_t key) { return TlsGetValue(key); }
+#endif
 #endif /* _WIN32 */
 
 #include "civetweb.h"
@@ -1453,13 +1455,23 @@ static void sockaddr_to_string(char *buf, size_t len, const union usa *usa)
 	}
 
 	if (usa->sa.sa_family == AF_INET) {
-		getnameinfo(
-		    &usa->sa, sizeof(usa->sin), buf, len, NULL, 0, NI_NUMERICHOST);
+		getnameinfo(&usa->sa,
+		            sizeof(usa->sin),
+		            buf,
+		            (unsigned)len,
+		            NULL,
+		            0,
+		            NI_NUMERICHOST);
 	}
 #if defined(USE_IPV6)
 	else if (usa->sa.sa_family == AF_INET6) {
-		getnameinfo(
-		    &usa->sa, sizeof(usa->sin6), buf, len, NULL, 0, NI_NUMERICHOST);
+		getnameinfo(&usa->sa,
+		            sizeof(usa->sin6),
+		            buf,
+		            (unsigned)len,
+		            NULL,
+		            0,
+		            NI_NUMERICHOST);
 	}
 #endif
 
@@ -2087,6 +2099,7 @@ static int pthread_mutex_lock(pthread_mutex_t *mutex)
 	return WaitForSingleObject(*mutex, INFINITE) == WAIT_OBJECT_0 ? 0 : -1;
 }
 
+#ifdef ENABLE_UNUSED_PTHREAD_FUNCTIONS
 static int pthread_mutex_trylock(pthread_mutex_t *mutex)
 {
 	switch (WaitForSingleObject(*mutex, 0)) {
@@ -2097,6 +2110,7 @@ static int pthread_mutex_trylock(pthread_mutex_t *mutex)
 	}
 	return -1;
 }
+#endif
 
 static int pthread_mutex_unlock(pthread_mutex_t *mutex)
 {
@@ -2170,9 +2184,9 @@ static int pthread_cond_timedwait(pthread_cond_t *cv,
 
 	if (abstime) {
 		clock_gettime(CLOCK_REALTIME, &tsnow);
-		nsnow = (((uint64_t)tsnow.tv_sec) * 1000000000) + tsnow.tv_nsec;
+		nsnow = (((int64_t)tsnow.tv_sec) * 1000000000) + tsnow.tv_nsec;
 		nswaitabs =
-		    (((uint64_t)abstime->tv_sec) * 1000000000) + abstime->tv_nsec;
+		    (((int64_t)abstime->tv_sec) * 1000000000) + abstime->tv_nsec;
 		nswaitrel = nswaitabs - nsnow;
 		if (nswaitrel < 0)
 			nswaitrel = 0;
@@ -2477,11 +2491,12 @@ static struct dirent *readdir(DIR *dir)
 }
 
 #ifndef HAVE_POLL
-static int poll(struct pollfd *pfd, int n, int milliseconds)
+static int poll(struct pollfd *pfd, unsigned int n, int milliseconds)
 {
 	struct timeval tv;
 	fd_set set;
-	int i, result;
+	unsigned int i;
+	int result;
 	SOCKET maxfd = 0;
 
 	tv.tv_sec = milliseconds / 1000;
@@ -2509,11 +2524,11 @@ static int poll(struct pollfd *pfd, int n, int milliseconds)
 }
 #endif /* HAVE_POLL */
 
-static void set_close_on_exec(SOCKET sock,
+static void set_close_on_exec(int sock,
                               struct mg_connection *conn /* may be null */)
 {
 	(void)conn; /* Unused. */
-	(void)SetHandleInformation((HANDLE)sock, HANDLE_FLAG_INHERIT, 0);
+	(void)SetHandleInformation((HANDLE)(intptr_t)sock, HANDLE_FLAG_INHERIT, 0);
 }
 
 int mg_start_thread(mg_thread_func_t f, void *p)
@@ -2563,9 +2578,7 @@ static int mg_join_thread(pthread_t threadid)
 	result = -1;
 	dwevent = WaitForSingleObject(threadid, INFINITE);
 	if (dwevent == WAIT_FAILED) {
-		int err = GetLastError();
-		(void)err;
-		DEBUG_TRACE("WaitForSingleObject() failed, error %d", err);
+		DEBUG_TRACE("WaitForSingleObject() failed, error %d", ERRNO);
 	} else {
 		if (dwevent == WAIT_OBJECT_0) {
 			CloseHandle(threadid);
@@ -2601,8 +2614,8 @@ static int dlclose(void *handle)
 #define SIGKILL (0)
 static int kill(pid_t pid, int sig_num)
 {
-	(void)TerminateProcess(pid, sig_num);
-	(void)CloseHandle(pid);
+	(void)TerminateProcess((HANDLE)pid, (UINT)sig_num);
+	(void)CloseHandle((HANDLE)pid);
 	return 0;
 }
 
@@ -2721,7 +2734,7 @@ static pid_t spawn_process(struct mg_connection *conn,
 static int set_non_blocking_mode(SOCKET sock)
 {
 	unsigned long on = 1;
-	return ioctlsocket(sock, FIONBIO, &on);
+	return ioctlsocket(sock, (long)FIONBIO, &on);
 }
 
 #else
@@ -4188,7 +4201,7 @@ static int parse_auth_header(struct mg_connection *conn,
 	if ((s == NULL) || (*s != 0)) {
 		return 0;
 	}
-	nonce ^= (unsigned long)(conn->ctx);
+	nonce ^= (uintptr_t)(conn->ctx);
 	if (nonce < conn->ctx->start_time) {
 		/* nonce is from a previous start of the server and no longer valid
 		 * (replay attack?) */
@@ -4419,7 +4432,7 @@ static void send_authorization_request(struct mg_connection *conn)
 		++conn->ctx->nonce_count;
 		(void)pthread_mutex_unlock(&conn->ctx->nonce_mutex);
 
-		nonce ^= (unsigned long)(conn->ctx);
+		nonce ^= (uintptr_t)(conn->ctx);
 		conn->status_code = 401;
 		conn->must_close = 1;
 
@@ -4582,7 +4595,7 @@ static SOCKET conn2(struct mg_context *ctx /* may be null */,
 		memset(&sain, '\0', sizeof(sain));
 		sain.sin_family = AF_INET;
 		sain.sin_port = htons((uint16_t)port);
-		sain.sin_addr = *(struct in_addr *)he->h_addr_list[0];
+		sain.sin_addr = *(struct in_addr *)(void *)he->h_addr_list[0];
 		if (connect(sock, (struct sockaddr *)&sain, sizeof(sain)) != 0) {
 			snprintf(ebuf,
 			         ebuf_len,
@@ -5469,7 +5482,7 @@ static char *addenv(struct cgi_env_block *block, const char *fmt, ...)
 		return NULL;
 
 	/* Calculate how much space is left in the buffer */
-	space = sizeof(block->buf) - block->len - 2;
+	space = (int)(sizeof(block->buf) - block->len) - 2;
 	/* assert(space >= 0); */
 	if (space < 0)
 		return NULL;
@@ -8595,7 +8608,7 @@ static int set_sock_timeout(SOCKET sock, int milliseconds)
 {
 	int r1, r2;
 #ifdef _WIN32
-	DWORD t = milliseconds;
+	DWORD t = (DWORD)milliseconds;
 #else
 #if defined(TCP_USER_TIMEOUT)
 	unsigned int uto = (unsigned int)milliseconds;
@@ -8774,7 +8787,7 @@ struct mg_connection *mg_connect_client(
 			       __func__,
 			       strerror(ERRNO));
 		}
-		conn->client.is_ssl = use_ssl;
+		conn->client.is_ssl = use_ssl ? 1 : 0;
 		(void)pthread_mutex_init(&conn->mutex, NULL);
 #ifndef NO_SSL
 		if (use_ssl) {
@@ -9227,6 +9240,7 @@ static void *worker_thread_run(void *thread_func_param)
 	struct mg_context *ctx = (struct mg_context *)thread_func_param;
 	struct mg_connection *conn;
 	struct mg_workerTLS tls;
+	uint32_t addr;
 
 	mg_set_thread_name("worker");
 
@@ -9265,10 +9279,8 @@ static void *worker_thread_run(void *thread_func_param)
 			                   sizeof(conn->request_info.remote_addr),
 			                   &conn->client.rsa);
 			/* TODO: #if defined(MG_LEGACY_INTERFACE) */
-			memcpy(&conn->request_info.remote_ip,
-			       &conn->client.rsa.sin.sin_addr.s_addr,
-			       4);
-			conn->request_info.remote_ip = ntohl(conn->request_info.remote_ip);
+			addr = ntohl(conn->client.rsa.sin.sin_addr.s_addr);
+			memcpy(&conn->request_info.remote_ip, &addr, 4);
 			/* #endif */
 			conn->request_info.is_ssl = conn->client.is_ssl;
 
@@ -9661,7 +9673,7 @@ struct mg_context *mg_start(const struct mg_callbacks *callbacks,
 {
 	struct mg_context *ctx;
 	const char *name, *value, *default_value;
-	int index, ok, workerthreadcount;
+	int idx, ok, workerthreadcount;
 	unsigned int i;
 	void (*exit_callback)(const struct mg_context *ctx) = 0;
 
@@ -9721,7 +9733,7 @@ struct mg_context *mg_start(const struct mg_callbacks *callbacks,
 #endif
 
 	while (options && (name = *options++) != NULL) {
-		if ((index = get_option_index(name)) == -1) {
+		if ((idx = get_option_index(name)) == -1) {
 			mg_cry(fc(ctx), "Invalid option: %s", name);
 			free_context(ctx);
 			return NULL;
@@ -9730,11 +9742,11 @@ struct mg_context *mg_start(const struct mg_callbacks *callbacks,
 			free_context(ctx);
 			return NULL;
 		}
-		if (ctx->config[index] != NULL) {
+		if (ctx->config[idx] != NULL) {
 			mg_cry(fc(ctx), "warning: %s: duplicate option", name);
-			mg_free(ctx->config[index]);
+			mg_free(ctx->config[idx]);
 		}
-		ctx->config[index] = mg_strdup(value);
+		ctx->config[idx] = mg_strdup(value);
 		DEBUG_TRACE("[%s] -> [%s]", name, value);
 	}
 

+ 45 - 33
src/main.c

@@ -35,6 +35,14 @@
 #define IGNORE_UNUSED_RESULT(a) ((void)((a) && 1))
 #endif
 
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+#define NO_RETURN [[noreturn]]
+#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
+#define NO_RETURN _Noreturn
+#else
+#define NO_RETURN
+#endif
+
 #include <sys/stat.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -131,7 +139,7 @@ static struct mg_option main_config_options[] = {
 
 static void WINCDECL signal_handler(int sig_num) { g_exit_flag = sig_num; }
 
-static void die(const char *fmt, ...)
+static NO_RETURN void die(const char *fmt, ...)
 {
 	va_list ap;
 	char msg[200] = "";
@@ -163,7 +171,7 @@ static void show_server_name(void)
 	fprintf(stderr, "CivetWeb v%s, built on %s\n", mg_version(), __DATE__);
 }
 
-static void show_usage_and_exit(const char *exeName)
+static NO_RETURN void show_usage_and_exit(const char *exeName)
 {
 	const struct mg_option *options;
 	int i;
@@ -247,6 +255,7 @@ static const char *get_url_to_first_open_port(const struct mg_context *ctx)
 	return url;
 }
 
+#ifdef ENABLE_CREATE_CONFIG_FILE
 static void create_config_file(const struct mg_context *ctx, const char *path)
 {
 	const struct mg_option *options;
@@ -269,6 +278,7 @@ static void create_config_file(const struct mg_context *ctx, const char *path)
 	}
 }
 #endif
+#endif
 
 static char *sdup(const char *str)
 {
@@ -352,7 +362,6 @@ static int set_option(char **options, const char *name, const char *value)
 		break;
 	default:
 		die("Unknown option type - option %s", name);
-		break;
 	}
 
 	for (i = 0; i < MAX_OPTIONS; i++) {
@@ -605,7 +614,7 @@ static void set_absolute_path(char *options[],
                               const char *option_name,
                               const char *path_to_civetweb_exe)
 {
-	char path[PATH_MAX] = "", abs[PATH_MAX] = "";
+	char path[PATH_MAX] = "", absolute[PATH_MAX] = "";
 	const char *option_value;
 	const char *p;
 
@@ -633,8 +642,8 @@ static void set_absolute_path(char *options[],
 		strncat(path, option_value, sizeof(path) - strlen(path) - 1);
 
 		/* Absolutize the path, and set the option */
-		IGNORE_UNUSED_RESULT(abs_path(path, abs, sizeof(abs)));
-		set_option(options, option_name, abs);
+		IGNORE_UNUSED_RESULT(abs_path(path, absolute, sizeof(absolute)));
+		set_option(options, option_name, absolute);
 	}
 }
 
@@ -878,7 +887,7 @@ static void show_error(void)
 
 static void *align(void *ptr, DWORD alig)
 {
-	ULONG ul = (ULONG)ptr;
+	uintptr_t ul = (uintptr_t)ptr;
 	ul += alig;
 	ul &= ~alig;
 	return ((void *)ul);
@@ -913,7 +922,7 @@ static void save_config(HWND hDlg, FILE *fp)
 	}
 }
 
-static BOOL CALLBACK
+static INT_PTR CALLBACK
 SettingsDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
 {
 	FILE *fp;
@@ -1070,7 +1079,8 @@ struct tstring_input_buf {
 	char *buffer;
 };
 
-static BOOL CALLBACK InputDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lP)
+static INT_PTR CALLBACK
+InputDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lP)
 {
 	static struct tstring_input_buf *inBuf = 0;
 	WORD ctrlId;
@@ -1085,8 +1095,9 @@ static BOOL CALLBACK InputDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lP)
 		ctrlId = LOWORD(wParam);
 		if (ctrlId == IDOK) {
 			/* Add user */
-			GetWindowText(
-			    GetDlgItem(hDlg, ID_INPUT_LINE), inBuf->buffer, inBuf->buflen);
+			GetWindowText(GetDlgItem(hDlg, ID_INPUT_LINE),
+			              inBuf->buffer,
+			              (int)inBuf->buflen);
 			if (strlen(inBuf->buffer) > 0) {
 				EndDialog(hDlg, IDOK);
 			}
@@ -1127,7 +1138,7 @@ static void suggest_passwd(char *passwd)
 
 	/* valid characters are 32 to 126 */
 	GetSystemTimeAsFileTime(&num.ft);
-	num.li.HighPart |= GetCurrentProcessId();
+	num.li.HighPart |= (LONG)GetCurrentProcessId();
 	p = passwd;
 	while (num.li.QuadPart) {
 		u = (unsigned)(num.li.QuadPart % 95);
@@ -1141,12 +1152,12 @@ static void suggest_passwd(char *passwd)
 static void add_control(unsigned char **mem,
                         DLGTEMPLATE *dia,
                         WORD type,
-                        DWORD id,
+                        WORD id,
                         DWORD style,
-                        WORD x,
-                        WORD y,
-                        WORD cx,
-                        WORD cy,
+                        short x,
+                        short y,
+                        short cx,
+                        short cy,
                         const char *caption);
 
 static int get_password(const char *user,
@@ -1290,7 +1301,7 @@ static int get_password(const char *user,
 	            12,
 	            "Cancel");
 
-	assert((int)p - (int)mem < (int)sizeof(mem));
+	assert((intptr_t)p - (intptr_t)mem < (intptr_t)sizeof(mem));
 
 	dia->cy = y + (WORD)(HEIGHT * 1.5);
 
@@ -1306,7 +1317,7 @@ static int get_password(const char *user,
 #undef LABEL_WIDTH
 }
 
-static BOOL CALLBACK
+static INT_PTR CALLBACK
 PasswordDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lP)
 {
 	static const char *passfile = 0;
@@ -1376,12 +1387,12 @@ PasswordDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lP)
 static void add_control(unsigned char **mem,
                         DLGTEMPLATE *dia,
                         WORD type,
-                        DWORD id,
+                        WORD id,
                         DWORD style,
-                        WORD x,
-                        WORD y,
-                        WORD cx,
-                        WORD cy,
+                        short x,
+                        short y,
+                        short cx,
+                        short cy,
                         const char *caption)
 {
 	DLGITEMTEMPLATE *tp;
@@ -1392,7 +1403,7 @@ static void add_control(unsigned char **mem,
 	*mem = align(*mem, 3);
 	tp = (DLGITEMTEMPLATE *)*mem;
 
-	tp->id = (WORD)id;
+	tp->id = id;
 	tp->style = style;
 	tp->dwExtendedStyle = 0;
 	tp->x = x;
@@ -1424,7 +1435,8 @@ static void show_settings_dialog()
 	const struct mg_option *options;
 	DWORD style;
 	DLGTEMPLATE *dia = (DLGTEMPLATE *)mem;
-	WORD i, cl, x, y, width, nelems = 0;
+	WORD i, cl, nelems = 0;
+	short width, x, y;
 
 	static struct {
 		DLGTEMPLATE template; /* 18 bytes */
@@ -1479,7 +1491,7 @@ static void show_settings_dialog()
 			            0x80,
 			            ID_CONTROLS + i + ID_FILE_BUTTONS_DELTA,
 			            WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
-			            (WORD)(x + width + LABEL_WIDTH + 5),
+			            x + width + LABEL_WIDTH + 5,
 			            y,
 			            15,
 			            12,
@@ -1503,17 +1515,17 @@ static void show_settings_dialog()
 		            cl,
 		            ID_CONTROLS + i,
 		            style,
-		            (WORD)(x + LABEL_WIDTH),
+		            x + LABEL_WIDTH,
 		            y,
 		            width,
 		            12,
 		            "");
 		nelems++;
 
-		assert(((int)p - (int)mem) < (int)sizeof(mem));
+		assert(((intptr_t)p - (intptr_t)mem) < (intptr_t)sizeof(mem));
 	}
 
-	y = (WORD)(((nelems + 1) / 2 + 1) * HEIGHT + 5);
+	y = (((nelems + 1) / 2 + 1) * HEIGHT + 5);
 	add_control(&p,
 	            dia,
 	            0x80,
@@ -1576,7 +1588,7 @@ static void show_settings_dialog()
 	            12,
 	            g_server_base_name);
 
-	assert(((int)p - (int)mem) < (int)sizeof(mem));
+	assert(((intptr_t)p - (intptr_t)mem) < (intptr_t)sizeof(mem));
 
 	dia->cy = ((nelems + 1) / 2 + 1) * HEIGHT + 30;
 	DialogBoxIndirectParam(NULL, dia, NULL, SettingsDlgProc, (LPARAM)NULL);
@@ -1715,7 +1727,7 @@ static void change_password_file()
 			            u);
 
 			nelems++;
-			assert(((int)p - (int)mem) < (int)sizeof(mem));
+			assert(((intptr_t)p - (intptr_t)mem) < (intptr_t)sizeof(mem));
 		}
 		fclose(f);
 
@@ -1777,7 +1789,7 @@ static void change_password_file()
 		            12,
 		            g_server_base_name);
 
-		assert(((int)p - (int)mem) < (int)sizeof(mem));
+		assert(((intptr_t)p - (intptr_t)mem) < (intptr_t)sizeof(mem));
 
 		dia->cy = y + 20;
 	} while ((IDOK == DialogBoxIndirectParam(

+ 7 - 5
src/mod_lua.inl

@@ -10,21 +10,23 @@ mmap(void *addr, int64_t len, int prot, int flags, int fd, int offset)
 	/* TODO: This is an incomplete implementation of mmap for windows.
 	 * Currently it is sufficient, but there are a lot of unused parameters.
 	 */
+	HANDLE fh = (HANDLE)_get_osfhandle(fd);
+	HANDLE mh = CreateFileMapping(fh, 0, PAGE_READONLY, 0, 0, 0);
+	void *p = MapViewOfFile(mh, FILE_MAP_READ, 0, 0, (size_t)len);
+	CloseHandle(mh);
+
+	/* unused parameters */
 	(void)addr;
 	(void)prot;
 	(void)flags;
 	(void)offset;
 
-	HANDLE fh = (HANDLE)_get_osfhandle(fd);
-	HANDLE mh = CreateFileMapping(fh, 0, PAGE_READONLY, 0, 0, 0);
-	void *p = MapViewOfFile(mh, FILE_MAP_READ, 0, 0, (size_t)len);
-	CloseHandle(mh);
 	return p;
 }
 
 static void munmap(void *addr, int64_t length)
 {
-
+	/* unused parameters */
 	(void)length;
 
 	UnmapViewOfFile(addr);