Clear warnings/errors within BN_CTX_DEBUG code sections
[openssl.git] / crypto / bn / bn_ctx.c
index 5bd742a97c102f1789def58ef25d95460874c179..d5eb02268d325a47e3f78c870d2c09f8856ae5ad 100644 (file)
@@ -60,7 +60,8 @@
 #endif
 #endif
 
-#include <stdio.h>
+
+
 #include <assert.h>
 
 #include "cryptlib.h"
@@ -158,10 +159,10 @@ static void ctxdbg(BN_CTX *ctx)
        unsigned int bnidx = 0, fpidx = 0;
        BN_POOL_ITEM *item = ctx->pool.head;
        BN_STACK *stack = &ctx->stack;
-       fprintf(stderr,"(%08x): ", (unsigned int)ctx);
+       fprintf(stderr,"(%16p): ", ctx);
        while(bnidx < ctx->used)
                {
-               fprintf(stderr,"%02x ", item->vals[bnidx++ % BN_CTX_POOL_SIZE].dmax);
+               fprintf(stderr,"%03x ", item->vals[bnidx++ % BN_CTX_POOL_SIZE].dmax);
                if(!(bnidx % BN_CTX_POOL_SIZE))
                        item = item->next;
                }
@@ -171,8 +172,8 @@ static void ctxdbg(BN_CTX *ctx)
        while(fpidx < stack->depth)
                {
                while(bnidx++ < stack->indexes[fpidx])
-                       fprintf(stderr,"   ");
-               fprintf(stderr,"^^ ");
+                       fprintf(stderr,"    ");
+               fprintf(stderr,"^^^ ");
                bnidx++;
                fpidx++;
                }
@@ -230,7 +231,10 @@ BN_CTX *BN_CTX_new(void)
 
 void BN_CTX_free(BN_CTX *ctx)
        {
+       if (ctx == NULL)
+               return;
 #ifdef BN_CTX_DEBUG
+       {
        BN_POOL_ITEM *pool = ctx->pool.head;
        fprintf(stderr,"BN_CTX_free, stack-size=%d, pool-bignums=%d\n",
                ctx->stack.size, ctx->pool.size);
@@ -242,6 +246,7 @@ void BN_CTX_free(BN_CTX *ctx)
                pool = pool->next;
        }
        fprintf(stderr,"\n");
+       }
 #endif
        BN_STACK_finish(&ctx->stack);
        BN_POOL_finish(&ctx->pool);
@@ -257,8 +262,7 @@ void BN_CTX_start(BN_CTX *ctx)
        /* (Try to) get a new frame pointer */
        else if(!BN_STACK_push(&ctx->stack, ctx->used))
                {
-               /* I know this isn't BN_CTX_get, but ... */
-               BNerr(BN_F_BN_CTX_GET,BN_R_TOO_MANY_TEMPORARY_VARIABLES);
+               BNerr(BN_F_BN_CTX_START,BN_R_TOO_MANY_TEMPORARY_VARIABLES);
                ctx->err_stack++;
                }
        CTXDBG_EXIT(ctx);