silc_stack_alloc automatically aligns the stack size.
[silc.git] / lib / silcutil / silcstack.c
index 509331f28a50c506102e4bed61cfc12cdece59b7..79f63d2fc8552242223be51cadbccb5c69d7ff40 100644 (file)
@@ -177,6 +177,9 @@ SilcStack silc_stack_alloc(SilcUInt32 stack_size, SilcStack parent)
   if (stack_size < SILC_STACK_DEFAULT_SIZE)
     stack_size = SILC_STACK_DEFAULT_SIZE;
 
+  /* Align by 8 */
+  stack_size += ((-stack_size) % 8);
+
   if (parent) {
     /* Get stack from parent.  The stack itself is allocated from the
        parent (but does not consume parent's own stack). */
@@ -497,7 +500,7 @@ void *silc_stack_realloc(SilcStack stack, SilcUInt32 old_size,
   if (stack->stack->data[si]->bytes_left + old_size +
       ((unsigned char *)ptr - (unsigned char *)sptr) != bsize) {
     SILC_LOG_DEBUG(("Cannot reallocate"));
-    silc_set_errno_nofail(SILC_ERR_BAD_ADDRESS);
+    silc_set_errno_nofail(SILC_ERR_INVALID_ARGUMENT);
     SILC_STACK_STAT(stack, num_errors, 1);
     return NULL;
   }
@@ -512,7 +515,8 @@ void *silc_stack_realloc(SilcStack stack, SilcUInt32 old_size,
   }
 
   SILC_LOG_DEBUG(("Cannot reallocate in this block"));
-  silc_set_errno_nofail(SILC_ERR_OUT_OF_MEMORY);
+  silc_set_errno_reason_nofail(SILC_ERR_TOO_LARGE_ALLOCATION,
+                              "Cannot reallocate in this memory block");
   SILC_STACK_STAT(stack, num_errors, 1);
   return NULL;
 }