fixed copying HTTP response buffer for Emscripten platform 4.3.2.1
authorHolger Schemel <info@artsoft.org>
Mon, 18 Apr 2022 21:44:19 +0000 (23:44 +0200)
committerHolger Schemel <info@artsoft.org>
Mon, 18 Apr 2022 22:23:13 +0000 (00:23 +0200)
src/libgame/http.c

index 333ef2a3147da46ce245156d943f42fb0725e2a7..c83c91f71b1515695da8540a0f7c384b9c4f74ea 100644 (file)
@@ -65,18 +65,18 @@ static void SetHttpResponseToDefaults(struct HttpResponse *response)
   response->status_text[0] = '\0';
 }
 
-struct HttpResponse *GetHttpResponseFromBuffer(void *buffer, int size)
+struct HttpResponse *GetHttpResponseFromBuffer(void *buffer, int body_size)
 {
-  if (size > MAX_HTTP_BODY_SIZE)
+  if (body_size > MAX_HTTP_BODY_SIZE)
     return NULL;
 
   struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse));
 
   SetHttpResponseToDefaults(response);
 
-  strncpy(response->body, buffer, MAX_HTTP_BODY_SIZE);
-  response->body[MAX_HTTP_BODY_SIZE] = '\0';
-  response->body_size = MIN(size, MAX_HTTP_BODY_SIZE);
+  memcpy(response->body, buffer, body_size);
+  response->body[body_size] = '\0';
+  response->body_size = body_size;
 
   return response;
 }