bel2125 5 rokov pred
rodič
commit
1beb379c99
5 zmenil súbory, kde vykonal 31 pridanie a 16 odobranie
  1. 1 1
      examples/embedded_c/embedded_c.c
  2. 3 5
      src/civetweb.c
  3. 1 3
      src/handle_form.inl
  4. 25 6
      src/main.c
  5. 1 1
      src/mod_lua.inl

+ 1 - 1
examples/embedded_c/embedded_c.c

@@ -44,7 +44,7 @@
 
 #define EXAMPLE_URI "/example"
 #define EXIT_URI "/exit"
-int exitNow = 0;
+volatile int exitNow = 0;
 
 
 int

+ 3 - 5
src/civetweb.c

@@ -4790,8 +4790,8 @@ mg_send_http_error_impl(struct mg_connection *conn,
 					 */
 					path_buf[sizeof(path_buf) - 32] = 0;
 					len = (int)strlen(path_buf);
-					if (len > sizeof(path_buf) - 32) {
-						len = sizeof(path_buf) - 32;
+					if (len > (int)sizeof(path_buf) - 32) {
+						len = (int)sizeof(path_buf) - 32;
 					}
 
 					/* Start with the file extenstion from the configuration. */
@@ -11694,7 +11694,6 @@ put_file(struct mg_connection *conn, const char *path)
 			/* Check if the server may write this file */
 			if (access(path, W_OK) == 0) {
 				/* Access granted */
-				conn->status_code = 200;
 				rc = 1;
 			} else {
 				mg_send_http_error(
@@ -16038,8 +16037,7 @@ static int
 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;
+	struct mg_domain_context *dom = ((ctx != NULL) ? &(ctx->dd) : NULL);
 
 #if defined(GCC_DIAGNOSTIC)
 #pragma GCC diagnostic push

+ 1 - 3
src/handle_form.inl

@@ -962,9 +962,7 @@ mg_handle_form_request(struct mg_connection *conn,
 					mg_free(boundary);
 					return -1;
 				}
-				if (r == 0) {
-					all_data_read = (buf_fill == 0);
-				}
+				/* r==0 already handled, all_data_read is false here */
 
 				buf_fill += r;
 				buf[buf_fill] = 0;

+ 25 - 6
src/main.c

@@ -649,6 +649,7 @@ set_option(char **options, const char *name, const char *value)
 		{
 			char *chk = 0;
 			unsigned long num = strtoul(value, &chk, 10);
+			(void)num; /* do not check value, only syntax */
 			if ((chk == NULL) || (*chk != 0) || (chk == value)) {
 				/* invalid number */
 				return 0;
@@ -2981,11 +2982,14 @@ WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 }
 
 
+/* An executable with "Subsystem: Windows" does not have a Console.
+ * Create one manually, if required. */
 static int
 MakeConsole(void)
 {
 	DWORD err;
 	HANDLE hConWnd = GetConsoleWindow();
+	int ok = 1;
 
 	if (hConWnd == NULL) {
 		if (!AttachConsole(ATTACH_PARENT_PROCESS)) {
@@ -2993,6 +2997,7 @@ MakeConsole(void)
 			if (!AllocConsole()) {
 				err = GetLastError();
 				if (err == ERROR_ACCESS_DENIED) {
+					ok = 0;
 					MessageBox(NULL,
 					           "Insufficient rights to create a console window",
 					           "Error",
@@ -3005,24 +3010,35 @@ MakeConsole(void)
 		/* Retry to get a console handle */
 		hConWnd = GetConsoleWindow();
 
-		if (hConWnd != NULL) {
+		if (hConWnd == NULL) {
+			ok = 0;
+		} else {
 			/* Reopen console handles according to
 			 * https://stackoverflow.com/questions/9020790/using-stdin-with-an-allocconsole
 			 */
-			freopen("CONIN$", "r", stdin);
-			freopen("CONOUT$", "w", stdout);
-			freopen("CONOUT$", "w", stderr);
+			if (NULL == freopen("CONIN$", "r", stdin)) {
+				ok = 0;
+			}
+			if (NULL == freopen("CONOUT$", "w", stdout)) {
+				ok = 0;
+			}
+			if (NULL == freopen("CONOUT$", "w", stderr)) {
+				ok = 0;
+			}
 		}
 	}
 
-	if (hConWnd != NULL) {
+	if (hConWnd == NULL) {
+		ok = 0;
+	} else {
 		SetConsoleTitle(g_server_name);
 	}
 
-	return (hConWnd != NULL);
+	return ok;
 }
 
 
+/* main() for Windows (Subsystem: Windows). */
 int WINAPI
 WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR cmdline, int show)
 {
@@ -3100,6 +3116,7 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR cmdline, int show)
 }
 
 
+/* main() for Windows (Subsystem: Console). */
 int
 main(int argc, char *argv[])
 {
@@ -3215,6 +3232,8 @@ main(int argc, char *argv[])
 
 #else
 
+
+/* main for Linux (and others) */
 int
 main(int argc, char *argv[])
 {

+ 1 - 1
src/mod_lua.inl

@@ -1122,7 +1122,7 @@ lsp_get_var(lua_State *L)
 	lua_gettable(L, LUA_REGISTRYINDEX);
 	ctx = (struct mg_context *)lua_touserdata(L, -1);
 
-	if (num_args >= 2 && num_args <= 3) {
+	if ((num_args >= 2) && (num_args <= 3)) {
 		char *dst;
 		data = lua_tolstring(L, 1, &data_len);
 		var_name = lua_tostring(L, 2);