lib: append: cleanup

This simplifies the use of the append() function and
fixes the error code on failure.

Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
diff --git a/lib/decoding.c b/lib/decoding.c
index e687508..d57aa93 100644
--- a/lib/decoding.c
+++ b/lib/decoding.c
@@ -2144,9 +2144,12 @@
 
 static int append(uint8_t **dst, unsigned *dst_size, const unsigned char *src, unsigned src_size)
 {
+  if (src_size == 0)
+    return ASN1_SUCCESS;
+
   *dst = _asn1_realloc(*dst, *dst_size+src_size);
   if (*dst == NULL)
-    return ASN1_MEM_ERROR;
+    return ASN1_MEM_ALLOC_ERROR;
   memcpy(*dst + *dst_size, src, src_size);
   *dst_size += src_size;
   return ASN1_SUCCESS;
@@ -2278,14 +2281,11 @@
 
           DECR_LEN(der_len, 2); /* we need the EOC */
 
-	  if (out_len > 0)
-	    {
-              result = append(&total, &total_size, out, out_len);
-              if (result != ASN1_SUCCESS)
-                {
-                  warn();
-                  goto cleanup;
-                }
+          result = append(&total, &total_size, out, out_len);
+          if (result != ASN1_SUCCESS)
+            {
+              warn();
+              goto cleanup;
 	    }
 
           free(out);
@@ -2331,6 +2331,13 @@
           goto cleanup;
         }
 
+      if (out_len == 0)
+        {
+          warn();
+          result = ASN1_DER_ERROR;
+          goto cleanup;
+        }
+
       result = append(&total, &total_size, cout, out_len);
       if (result != ASN1_SUCCESS)
         {