فهرست منبع

Fix more PSV Studio warnings

bel2125 5 سال پیش
والد
کامیت
13848d2d72
2فایلهای تغییر یافته به همراه12 افزوده شده و 5 حذف شده
  1. 10 3
      src/civetweb.c
  2. 2 2
      src/handle_form.inl

+ 10 - 3
src/civetweb.c

@@ -5238,7 +5238,7 @@ change_slashes_to_backslashes(char *path)
 
 		/* remove double backslash (check i > 0 to preserve UNC paths,
 		 * like \\server\file.txt) */
-		if ((path[i] == '\\') && (i > 0)) {
+		if ((i > 0) && (path[i] == '\\')) {
 			while ((path[i + 1] == '\\') || (path[i + 1] == '/')) {
 				(void)memmove(path + i + 1, path + i + 2, strlen(path + i + 1));
 			}
@@ -7901,12 +7901,17 @@ remove_dot_segments(char *inout)
 	/* Windows backend protection
 	 * (https://tools.ietf.org/html/rfc3986#section-7.3): Replace backslash in
 	 * URI by slash */
-	char *in_copy = mg_strdup(inout);
+	char *in_copy = inout ? mg_strdup(inout) : NULL;
 	char *out_begin = inout;
 	char *out_end = inout;
 	char *in = in_copy;
 	int replaced;
 
+	if (!in) {
+		/* Param error or OOM. */
+		return;
+	}
+
 	while (*in) {
 		if (*in == '\\') {
 			*in = '/';
@@ -19852,7 +19857,9 @@ mg_get_system_info(char *buffer, int buflen)
 	if (buflen > (int)(sizeof(eoobj) - 1)) {
 		/* has enough space to append eoobj */
 		append_eoobj = buffer;
-		end -= sizeof(eoobj) - 1;
+		if (end) {
+			end -= sizeof(eoobj) - 1;
+		}
 	}
 
 	system_info_length += mg_str_append(&buffer, end, "{");

+ 2 - 2
src/handle_form.inl

@@ -683,7 +683,7 @@ mg_handle_form_request(struct mg_connection *conn,
 
 			if (part_no == 0) {
 				int d = 0;
-				while ((buf[d] != '-') && (d < buf_fill)) {
+				while ((d < buf_fill) && (buf[d] != '-')) {
 					d++;
 				}
 				if ((d > 0) && (buf[d] == '-')) {
@@ -979,7 +979,7 @@ mg_handle_form_request(struct mg_connection *conn,
 				}
 			}
 
-			towrite = (size_t)(next - hend);
+			towrite = (next ? (size_t)(next - hend) : 0);
 
 			if (field_storage == MG_FORM_FIELD_STORAGE_GET) {
 				/* Call callback */