Explicitly test against NULL; do not use !p or similar
[openssl.git] / crypto / cms / cms_lib.c
index c2cac260109d1f6dd3f6eb2fcdc53fa5fdbc5a60..245544e3e9a2f054551f86ae3d7a451b31455be5 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.
  *
- * Licensed under the OpenSSL license (the "License").  You may not use
+ * Licensed under the Apache License 2.0 (the "License").  You may not use
  * this file except in compliance with the License.  You can obtain a copy
  * in the file LICENSE in the source distribution or at
  * https://www.openssl.org/source/license.html
@@ -14,7 +14,7 @@
 #include <openssl/bio.h>
 #include <openssl/asn1.h>
 #include <openssl/cms.h>
-#include "cms_lcl.h"
+#include "cms_local.h"
 
 IMPLEMENT_ASN1_FUNCTIONS(CMS_ContentInfo)
 IMPLEMENT_ASN1_PRINT_FUNCTION(CMS_ContentInfo)
@@ -39,15 +39,16 @@ CMS_ContentInfo *cms_Data_create(void)
 BIO *cms_content_bio(CMS_ContentInfo *cms)
 {
     ASN1_OCTET_STRING **pos = CMS_get0_content(cms);
-    if (!pos)
+
+    if (pos == NULL)
         return NULL;
     /* If content detached data goes nowhere: create NULL BIO */
-    if (!*pos)
+    if (*pos == NULL)
         return BIO_new(BIO_s_null());
     /*
      * If content not detached and created return memory BIO
      */
-    if (!*pos || ((*pos)->flags == ASN1_STRING_FLAG_CONT))
+    if (*pos == NULL || ((*pos)->flags == ASN1_STRING_FLAG_CONT))
         return BIO_new(BIO_s_mem());
     /* Else content was read in: return read only BIO for it */
     return BIO_new_mem_buf((*pos)->data, (*pos)->length);
@@ -104,10 +105,12 @@ BIO *CMS_dataInit(CMS_ContentInfo *cms, BIO *icont)
 
 }
 
+/* unfortunately cannot constify SMIME_write_ASN1() due to this function */
 int CMS_dataFinal(CMS_ContentInfo *cms, BIO *cmsbio)
 {
     ASN1_OCTET_STRING **pos = CMS_get0_content(cms);
-    if (!pos)
+
+    if (pos == NULL)
         return 0;
     /* If embedded content find memory BIO and set content */
     if (*pos && ((*pos)->flags & ASN1_STRING_FLAG_CONT)) {
@@ -233,13 +236,14 @@ const ASN1_OBJECT *CMS_get0_eContentType(CMS_ContentInfo *cms)
 int CMS_set1_eContentType(CMS_ContentInfo *cms, const ASN1_OBJECT *oid)
 {
     ASN1_OBJECT **petype, *etype;
+
     petype = cms_get0_econtent_type(cms);
-    if (!petype)
+    if (petype == NULL)
         return 0;
-    if (!oid)
+    if (oid == NULL)
         return 1;
     etype = OBJ_dup(oid);
-    if (!etype)
+    if (etype == NULL)
         return 0;
     ASN1_OBJECT_free(*petype);
     *petype = etype;
@@ -249,10 +253,11 @@ int CMS_set1_eContentType(CMS_ContentInfo *cms, const ASN1_OBJECT *oid)
 int CMS_is_detached(CMS_ContentInfo *cms)
 {
     ASN1_OCTET_STRING **pos;
+
     pos = CMS_get0_content(cms);
-    if (!pos)
+    if (pos == NULL)
         return -1;
-    if (*pos)
+    if (*pos != NULL)
         return 0;
     return 1;
 }
@@ -260,8 +265,9 @@ int CMS_is_detached(CMS_ContentInfo *cms)
 int CMS_set_detached(CMS_ContentInfo *cms, int detached)
 {
     ASN1_OCTET_STRING **pos;
+
     pos = CMS_get0_content(cms);
-    if (!pos)
+    if (pos == NULL)
         return 0;
     if (detached) {
         ASN1_OCTET_STRING_free(*pos);
@@ -361,12 +367,13 @@ CMS_CertificateChoices *CMS_add0_CertificateChoices(CMS_ContentInfo *cms)
 {
     STACK_OF(CMS_CertificateChoices) **pcerts;
     CMS_CertificateChoices *cch;
+
     pcerts = cms_get0_certificate_choices(cms);
-    if (!pcerts)
+    if (pcerts == NULL)
         return NULL;
-    if (!*pcerts)
+    if (*pcerts == NULL)
         *pcerts = sk_CMS_CertificateChoices_new_null();
-    if (!*pcerts)
+    if (*pcerts == NULL)
         return NULL;
     cch = M_ASN1_new_of(CMS_CertificateChoices);
     if (!cch)
@@ -383,8 +390,9 @@ int CMS_add0_cert(CMS_ContentInfo *cms, X509 *cert)
     CMS_CertificateChoices *cch;
     STACK_OF(CMS_CertificateChoices) **pcerts;
     int i;
+
     pcerts = cms_get0_certificate_choices(cms);
-    if (!pcerts)
+    if (pcerts == NULL)
         return 0;
     for (i = 0; i < sk_CMS_CertificateChoices_num(*pcerts); i++) {
         cch = sk_CMS_CertificateChoices_value(*pcerts, i);
@@ -438,15 +446,16 @@ CMS_RevocationInfoChoice *CMS_add0_RevocationInfoChoice(CMS_ContentInfo *cms)
 {
     STACK_OF(CMS_RevocationInfoChoice) **pcrls;
     CMS_RevocationInfoChoice *rch;
+
     pcrls = cms_get0_revocation_choices(cms);
-    if (!pcrls)
+    if (pcrls == NULL)
         return NULL;
-    if (!*pcrls)
+    if (*pcrls == NULL)
         *pcrls = sk_CMS_RevocationInfoChoice_new_null();
-    if (!*pcrls)
+    if (*pcrls == NULL)
         return NULL;
     rch = M_ASN1_new_of(CMS_RevocationInfoChoice);
-    if (!rch)
+    if (rch == NULL)
         return NULL;
     if (!sk_CMS_RevocationInfoChoice_push(*pcrls, rch)) {
         M_ASN1_free_of(rch, CMS_RevocationInfoChoice);
@@ -481,8 +490,9 @@ STACK_OF(X509) *CMS_get1_certs(CMS_ContentInfo *cms)
     CMS_CertificateChoices *cch;
     STACK_OF(CMS_CertificateChoices) **pcerts;
     int i;
+
     pcerts = cms_get0_certificate_choices(cms);
-    if (!pcerts)
+    if (pcerts == NULL)
         return NULL;
     for (i = 0; i < sk_CMS_CertificateChoices_num(*pcerts); i++) {
         cch = sk_CMS_CertificateChoices_value(*pcerts, i);
@@ -509,8 +519,9 @@ STACK_OF(X509_CRL) *CMS_get1_crls(CMS_ContentInfo *cms)
     STACK_OF(CMS_RevocationInfoChoice) **pcrls;
     CMS_RevocationInfoChoice *rch;
     int i;
+
     pcrls = cms_get0_revocation_choices(cms);
-    if (!pcrls)
+    if (pcrls == NULL)
         return NULL;
     for (i = 0; i < sk_CMS_RevocationInfoChoice_num(*pcrls); i++) {
         rch = sk_CMS_RevocationInfoChoice_value(*pcrls, i);