]> granicus.if.org Git - curl/commitdiff
mime: make Curl_mime_duppart() assert if called without valid dst
authorDaniel Stenberg <daniel@haxx.se>
Thu, 19 Sep 2019 08:06:01 +0000 (10:06 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 20 Sep 2019 06:07:31 +0000 (08:07 +0200)
Fixes warning detected by PVS-Studio
Fixes #4374

lib/mime.c

index 0fb3ae81c1692298c55e08edd5d59bae9d1e7b20..081e51e508930d35a937a89c69273b56c19f8b53 100644 (file)
@@ -1135,6 +1135,8 @@ CURLcode Curl_mime_duppart(curl_mimepart *dst, const curl_mimepart *src)
   const curl_mimepart *s;
   CURLcode res = CURLE_OK;
 
+  DEBUGASSERT(dst);
+
   /* Duplicate content. */
   switch(src->kind) {
   case MIMEKIND_NONE:
@@ -1184,20 +1186,18 @@ CURLcode Curl_mime_duppart(curl_mimepart *dst, const curl_mimepart *src)
     }
   }
 
-  /* Duplicate other fields. */
-  if(dst != NULL)
+  if(!res) {
+    /* Duplicate other fields. */
     dst->encoder = src->encoder;
-  else
-    res = CURLE_WRITE_ERROR;
-  if(!res)
     res = curl_mime_type(dst, src->mimetype);
+  }
   if(!res)
     res = curl_mime_name(dst, src->name);
   if(!res)
     res = curl_mime_filename(dst, src->filename);
 
   /* If an error occurred, rollback. */
-  if(res && dst)
+  if(res)
     Curl_mime_cleanpart(dst);
 
   return res;