Fix some style issues
authorMatt Caswell <matt@openssl.org>
Thu, 12 Nov 2015 11:50:38 +0000 (11:50 +0000)
committerMatt Caswell <matt@openssl.org>
Fri, 20 Nov 2015 23:37:17 +0000 (23:37 +0000)
There were a number of places where the async code did not conform to the
OpenSSL coding style.

Reviewed-by: Rich Salz <rsalz@openssl.org>
crypto/async/arch/async_posix.c
crypto/async/arch/async_win.c
crypto/async/async.c

index 814930f7bb56425712719eff5834754847fde895..78bf61c44ef25adb8f14e707d00b6c56c9af427e 100644 (file)
@@ -76,7 +76,8 @@ int async_fibre_init(async_fibre *fibre)
 {
     void *stack = NULL;
 
 {
     void *stack = NULL;
 
-    if (!(stack = OPENSSL_malloc(STACKSIZE))) {
+    stack = OPENSSL_malloc(STACKSIZE);
+    if (stack == NULL) {
         return 0;
     }
 
         return 0;
     }
 
index 5cb14ce9867b43d5fda68f6c3ed69f6a8123846a..fce3c481d66ea08f0253118366d17066f23ec955 100644 (file)
@@ -72,7 +72,7 @@ int async_fibre_init_dispatcher(async_fibre *fibre)
 
     dispatcher =
         (LPVOID) CRYPTO_get_thread_local(CRYPTO_THREAD_LOCAL_ASYNC_DISPATCH);
 
     dispatcher =
         (LPVOID) CRYPTO_get_thread_local(CRYPTO_THREAD_LOCAL_ASYNC_DISPATCH);
-    if (!dispatcher) {
+    if (dispatcher == NULL) {
         fibre->fibre = ConvertThreadToFiber(NULL);
         CRYPTO_set_thread_local(CRYPTO_THREAD_LOCAL_ASYNC_DISPATCH,
                                 (void *)fibre->fibre);
         fibre->fibre = ConvertThreadToFiber(NULL);
         CRYPTO_set_thread_local(CRYPTO_THREAD_LOCAL_ASYNC_DISPATCH,
                                 (void *)fibre->fibre);
@@ -125,7 +125,7 @@ int async_set_pool(STACK_OF(ASYNC_JOB) *poolin, size_t curr_size,
 {
     struct winpool *pool;
     pool = OPENSSL_malloc(sizeof *pool);
 {
     struct winpool *pool;
     pool = OPENSSL_malloc(sizeof *pool);
-    if (!pool)
+    if (pool == NULL)
         return 0;
 
     pool->pool = poolin;
         return 0;
 
     pool->pool = poolin;
index 9b9963fb5ed4625315eb7bc989385a6d7adcdd85..86f4c09675412b1dd27cd344481a38f0bd2459c3 100644 (file)
@@ -73,7 +73,8 @@ static async_ctx *async_ctx_new(void)
 {
     async_ctx *nctx = NULL;
 
 {
     async_ctx *nctx = NULL;
 
-    if(!(nctx = OPENSSL_malloc(sizeof (async_ctx)))) {
+    nctx = OPENSSL_malloc(sizeof (async_ctx));
+    if (nctx == NULL) {
         ASYNCerr(ASYNC_F_ASYNC_CTX_NEW, ERR_R_MALLOC_FAILURE);
         goto err;
     }
         ASYNCerr(ASYNC_F_ASYNC_CTX_NEW, ERR_R_MALLOC_FAILURE);
         goto err;
     }
@@ -81,27 +82,27 @@ static async_ctx *async_ctx_new(void)
     async_fibre_init_dispatcher(&nctx->dispatcher);
     nctx->currjob = NULL;
     nctx->blocked = 0;
     async_fibre_init_dispatcher(&nctx->dispatcher);
     nctx->currjob = NULL;
     nctx->blocked = 0;
-    if(!async_set_ctx(nctx))
+    if (!async_set_ctx(nctx))
         goto err;
 
     return nctx;
 err:
         goto err;
 
     return nctx;
 err:
-    if(nctx) {
-        OPENSSL_free(nctx);
-    }
+    OPENSSL_free(nctx);
 
     return NULL;
 }
 
 static int async_ctx_free(void)
 {
 
     return NULL;
 }
 
 static int async_ctx_free(void)
 {
-    if(async_get_ctx()) {
-        OPENSSL_free(async_get_ctx());
-    }
+    async_ctx *ctx;
 
 
-    if(!async_set_ctx(NULL))
+    ctx = async_get_ctx();
+
+    if (!async_set_ctx(NULL))
         return 0;
 
         return 0;
 
+    OPENSSL_free(ctx);
+
     return 1;
 }
 
     return 1;
 }
 
@@ -110,12 +111,13 @@ static ASYNC_JOB *async_job_new(void)
     ASYNC_JOB *job = NULL;
     int pipefds[2];
 
     ASYNC_JOB *job = NULL;
     int pipefds[2];
 
-    if(!(job = OPENSSL_malloc(sizeof (ASYNC_JOB)))) {
+    job = OPENSSL_malloc(sizeof (ASYNC_JOB));
+    if (job == NULL) {
         ASYNCerr(ASYNC_F_ASYNC_JOB_NEW, ERR_R_MALLOC_FAILURE);
         return NULL;
     }
 
         ASYNCerr(ASYNC_F_ASYNC_JOB_NEW, ERR_R_MALLOC_FAILURE);
         return NULL;
     }
 
-    if(!async_pipe(pipefds)) {
+    if (!async_pipe(pipefds)) {
         OPENSSL_free(job);
         ASYNCerr(ASYNC_F_ASYNC_JOB_NEW, ASYNC_R_CANNOT_CREATE_WAIT_PIPE);
         return NULL;
         OPENSSL_free(job);
         ASYNCerr(ASYNC_F_ASYNC_JOB_NEW, ASYNC_R_CANNOT_CREATE_WAIT_PIPE);
         return NULL;
@@ -133,9 +135,8 @@ static ASYNC_JOB *async_job_new(void)
 
 static void async_job_free(ASYNC_JOB *job)
 {
 
 static void async_job_free(ASYNC_JOB *job)
 {
-    if(job) {
-        if(job->funcargs)
-            OPENSSL_free(job->funcargs);
+    if (job != NULL) {
+        OPENSSL_free(job->funcargs);
         async_fibre_free(&job->fibrectx);
         OPENSSL_free(job);
     }
         async_fibre_free(&job->fibrectx);
         OPENSSL_free(job);
     }
@@ -172,8 +173,7 @@ static ASYNC_JOB *async_get_pool_job(void) {
 }
 
 static void async_release_job(ASYNC_JOB *job) {
 }
 
 static void async_release_job(ASYNC_JOB *job) {
-    if(job->funcargs)
-        OPENSSL_free(job->funcargs);
+    OPENSSL_free(job->funcargs);
     job->funcargs = NULL;
     /* Ignore error return */
     async_release_job_to_pool(job);
     job->funcargs = NULL;
     /* Ignore error return */
     async_release_job_to_pool(job);
@@ -190,8 +190,8 @@ void async_start_func(void)
 
         /* Stop the job */
         job->status = ASYNC_JOB_STOPPING;
 
         /* Stop the job */
         job->status = ASYNC_JOB_STOPPING;
-        if(!async_fibre_swapcontext(&job->fibrectx,
-                                    &async_get_ctx()->dispatcher, 1)) {
+        if (!async_fibre_swapcontext(&job->fibrectx,
+                                     &async_get_ctx()->dispatcher, 1)) {
             /*
              * Should not happen. Getting here will close the thread...can't do
              * much about it
             /*
              * Should not happen. Getting here will close the thread...can't do
              * much about it
@@ -204,17 +204,17 @@ void async_start_func(void)
 int ASYNC_start_job(ASYNC_JOB **job, int *ret, int (*func)(void *),
                          void *args, size_t size)
 {
 int ASYNC_start_job(ASYNC_JOB **job, int *ret, int (*func)(void *),
                          void *args, size_t size)
 {
-    if(!async_get_ctx() && !async_ctx_new()) {
+    if (async_get_ctx() == NULL && async_ctx_new() == NULL) {
         return ASYNC_ERR;
     }
 
         return ASYNC_ERR;
     }
 
-    if(*job) {
+    if (*job) {
         async_get_ctx()->currjob = *job;
     }
 
     for (;;) {
         async_get_ctx()->currjob = *job;
     }
 
     for (;;) {
-        if(async_get_ctx()->currjob) {
-            if(async_get_ctx()->currjob->status == ASYNC_JOB_STOPPING) {
+        if (async_get_ctx()->currjob != NULL) {
+            if (async_get_ctx()->currjob->status == ASYNC_JOB_STOPPING) {
                 *ret = async_get_ctx()->currjob->ret;
                 async_release_job(async_get_ctx()->currjob);
                 async_get_ctx()->currjob = NULL;
                 *ret = async_get_ctx()->currjob->ret;
                 async_release_job(async_get_ctx()->currjob);
                 async_get_ctx()->currjob = NULL;
@@ -222,18 +222,18 @@ int ASYNC_start_job(ASYNC_JOB **job, int *ret, int (*func)(void *),
                 return ASYNC_FINISH;
             }
 
                 return ASYNC_FINISH;
             }
 
-            if(async_get_ctx()->currjob->status == ASYNC_JOB_PAUSING) {
+            if (async_get_ctx()->currjob->status == ASYNC_JOB_PAUSING) {
                 *job = async_get_ctx()->currjob;
                 async_get_ctx()->currjob->status = ASYNC_JOB_PAUSED;
                 async_get_ctx()->currjob = NULL;
                 return ASYNC_PAUSE;
             }
 
                 *job = async_get_ctx()->currjob;
                 async_get_ctx()->currjob->status = ASYNC_JOB_PAUSED;
                 async_get_ctx()->currjob = NULL;
                 return ASYNC_PAUSE;
             }
 
-            if(async_get_ctx()->currjob->status == ASYNC_JOB_PAUSED) {
+            if (async_get_ctx()->currjob->status == ASYNC_JOB_PAUSED) {
                 async_get_ctx()->currjob = *job;
                 /* Resume previous job */
                 async_get_ctx()->currjob = *job;
                 /* Resume previous job */
-                if(!async_fibre_swapcontext(&async_get_ctx()->dispatcher,
-                    &async_get_ctx()->currjob->fibrectx, 1)) {
+                if (!async_fibre_swapcontext(&async_get_ctx()->dispatcher,
+                        &async_get_ctx()->currjob->fibrectx, 1)) {
                     ASYNCerr(ASYNC_F_ASYNC_START_JOB,
                              ASYNC_R_FAILED_TO_SWAP_CONTEXT);
                     goto err;
                     ASYNCerr(ASYNC_F_ASYNC_START_JOB,
                              ASYNC_R_FAILED_TO_SWAP_CONTEXT);
                     goto err;
@@ -250,13 +250,13 @@ int ASYNC_start_job(ASYNC_JOB **job, int *ret, int (*func)(void *),
         }
 
         /* Start a new job */
         }
 
         /* Start a new job */
-        if(!(async_get_ctx()->currjob = async_get_pool_job())) {
+        if ((async_get_ctx()->currjob = async_get_pool_job()) == NULL) {
             return ASYNC_NO_JOBS;
         }
 
             return ASYNC_NO_JOBS;
         }
 
-        if(args != NULL) {
+        if (args != NULL) {
             async_get_ctx()->currjob->funcargs = OPENSSL_malloc(size);
             async_get_ctx()->currjob->funcargs = OPENSSL_malloc(size);
-            if(!async_get_ctx()->currjob->funcargs) {
+            if (async_get_ctx()->currjob->funcargs == NULL) {
                 ASYNCerr(ASYNC_F_ASYNC_START_JOB, ERR_R_MALLOC_FAILURE);
                 async_release_job(async_get_ctx()->currjob);
                 async_get_ctx()->currjob = NULL;
                 ASYNCerr(ASYNC_F_ASYNC_START_JOB, ERR_R_MALLOC_FAILURE);
                 async_release_job(async_get_ctx()->currjob);
                 async_get_ctx()->currjob = NULL;
@@ -268,8 +268,8 @@ int ASYNC_start_job(ASYNC_JOB **job, int *ret, int (*func)(void *),
         }
 
         async_get_ctx()->currjob->func = func;
         }
 
         async_get_ctx()->currjob->func = func;
-        if(!async_fibre_swapcontext(&async_get_ctx()->dispatcher,
-            &async_get_ctx()->currjob->fibrectx, 1)) {
+        if (!async_fibre_swapcontext(&async_get_ctx()->dispatcher,
+                &async_get_ctx()->currjob->fibrectx, 1)) {
             ASYNCerr(ASYNC_F_ASYNC_START_JOB, ASYNC_R_FAILED_TO_SWAP_CONTEXT);
             goto err;
         }
             ASYNCerr(ASYNC_F_ASYNC_START_JOB, ASYNC_R_FAILED_TO_SWAP_CONTEXT);
             goto err;
         }
@@ -379,7 +379,9 @@ void ASYNC_free_pool(void)
 ASYNC_JOB *ASYNC_get_current_job(void)
 {
     async_ctx *ctx;
 ASYNC_JOB *ASYNC_get_current_job(void)
 {
     async_ctx *ctx;
-    if((ctx = async_get_ctx()) == NULL)
+
+    ctx = async_get_ctx();
+    if(ctx == NULL)
         return NULL;
 
     return ctx->currjob;
         return NULL;
 
     return ctx->currjob;