]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
mime: minor code cleanup
authorVictor Julien <vjulien@oisf.net>
Sun, 26 Jun 2022 20:43:38 +0000 (22:43 +0200)
committerVictor Julien <vjulien@oisf.net>
Wed, 29 Jun 2022 07:38:22 +0000 (09:38 +0200)
src/util-decode-mime.c

index cdcc5f90ecc06a43697b22810d7720964955b3a2..0f47cd16a409da688200b6946b706cac68a9aca6 100644 (file)
@@ -619,56 +619,34 @@ static void FreeDataValue(DataValue *dv)
  * allocated memory)
  *
  * \param dv The head of the linked list (NULL if new list)
- * \param len The output length of the single value
+ * \param olen The output length of the single value
  *
  * \return pointer to a single value, otherwise NULL if it fails or is zero-length
  */
-static uint8_t * GetFullValue(DataValue *dv, uint32_t *len)
+static uint8_t *GetFullValue(const DataValue *dv, uint32_t *olen)
 {
-    DataValue *curr;
     uint32_t offset = 0;
     uint8_t *val = NULL;
+    uint32_t len = 0;
+    *olen = 0;
 
     /* First calculate total length */
-    *len = 0;
-    curr = dv;
-    while (curr != NULL) {
-        *len += curr->value_len;
-
-#if 0
-        /* Add CRLF except on last one */
-        if (curr->next != NULL) {
-            *len += 2;
-        }
-#endif
-        curr = curr->next;
+    for (const DataValue *curr = dv; curr != NULL; curr = curr->next) {
+        len += curr->value_len;
     }
-
     /* Must have at least one character in the value */
-    if (*len > 0) {
-        val = SCCalloc(1, *len);
+    if (len > 0) {
+        val = SCCalloc(1, len);
         if (unlikely(val == NULL)) {
             SCLogError(SC_ERR_MEM_ALLOC, "memory allocation failed");
-            *len = 0;
             return NULL;
         }
-
-        curr = dv;
-        while (curr != NULL) {
+        for (const DataValue *curr = dv; curr != NULL; curr = curr->next) {
             memcpy(val + offset, curr->value, curr->value_len);
             offset += curr->value_len;
-
-#if 0       /* VJ unclear why this is needed ? */
-            /* Add CRLF except on last one */
-            if (curr->next != NULL) {
-                memcpy(val + offset, CRLF, 2);
-                offset += 2;
-            }
-#endif
-            curr = curr->next;
         }
     }
-
+    *olen = len;
     return val;
 }