free NULL cleanup 7
[openssl.git] / crypto / objects / obj_dat.c
index 0b06ea4a01470b91c09a8b27d5e13d6d14d9d234..46c4f878d1933a3c0bad00f463fafe6f4cf8b91f 100644 (file)
 #include <openssl/asn1.h>
 #include <openssl/objects.h>
 #include <openssl/bn.h>
+#include "internal/asn1_int.h"
 
 /* obj_dat.h is generated from objects.h by obj_dat.pl */
-#ifndef OPENSSL_NO_OBJECT
-# include "obj_dat.h"
-#else
-/* You will have to load all the objects needed manually in the application */
-# define NUM_NID 0
-# define NUM_SN 0
-# define NUM_LN 0
-# define NUM_OBJ 0
-static const unsigned char lvalues[1];
-static const ASN1_OBJECT nid_objs[1];
-static const unsigned int sn_objs[1];
-static const unsigned int ln_objs[1];
-static const unsigned int obj_objs[1];
-#endif
+#include "obj_dat.h"
 
 DECLARE_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, sn);
 DECLARE_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, ln);
@@ -267,21 +255,19 @@ int OBJ_add_object(const ASN1_OBJECT *obj)
             return (0);
     if ((o = OBJ_dup(obj)) == NULL)
         goto err;
-    if (!(ao[ADDED_NID] = (ADDED_OBJ *)OPENSSL_malloc(sizeof(ADDED_OBJ))))
+    if (!(ao[ADDED_NID] = OPENSSL_malloc(sizeof(ADDED_OBJ))))
         goto err2;
     if ((o->length != 0) && (obj->data != NULL))
         if (!
-            (ao[ADDED_DATA] = (ADDED_OBJ *)OPENSSL_malloc(sizeof(ADDED_OBJ))))
+            (ao[ADDED_DATA] = OPENSSL_malloc(sizeof(ADDED_OBJ))))
             goto err2;
     if (o->sn != NULL)
         if (!
-            (ao[ADDED_SNAME] =
-             (ADDED_OBJ *)OPENSSL_malloc(sizeof(ADDED_OBJ))))
+            (ao[ADDED_SNAME] = OPENSSL_malloc(sizeof(ADDED_OBJ))))
             goto err2;
     if (o->ln != NULL)
         if (!
-            (ao[ADDED_LNAME] =
-             (ADDED_OBJ *)OPENSSL_malloc(sizeof(ADDED_OBJ))))
+            (ao[ADDED_LNAME] = OPENSSL_malloc(sizeof(ADDED_OBJ))))
             goto err2;
 
     for (i = ADDED_DATA; i <= ADDED_NID; i++) {
@@ -462,7 +448,7 @@ ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name)
     /* Work out total size */
     j = ASN1_object_size(0, i, V_ASN1_OBJECT);
 
-    if ((buf = (unsigned char *)OPENSSL_malloc(j)) == NULL)
+    if ((buf = OPENSSL_malloc(j)) == NULL)
         return NULL;
 
     p = buf;
@@ -603,13 +589,11 @@ int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name)
         }
     }
 
-    if (bl)
-        BN_free(bl);
+    BN_free(bl);
     return n;
 
  err:
-    if (bl)
-        BN_free(bl);
+    BN_free(bl);
     return -1;
 }
 
@@ -778,7 +762,7 @@ int OBJ_create(const char *oid, const char *sn, const char *ln)
     if (i <= 0)
         return (0);
 
-    if ((buf = (unsigned char *)OPENSSL_malloc(i)) == NULL) {
+    if ((buf = OPENSSL_malloc(i)) == NULL) {
         OBJerr(OBJ_F_OBJ_CREATE, ERR_R_MALLOC_FAILURE);
         return (0);
     }
@@ -794,3 +778,17 @@ int OBJ_create(const char *oid, const char *sn, const char *ln)
     OPENSSL_free(buf);
     return (ok);
 }
+
+size_t OBJ_length(const ASN1_OBJECT *obj)
+{
+    if (obj == NULL)
+        return 0;
+    return obj->length;
+}
+
+const unsigned char *OBJ_get0_data(const ASN1_OBJECT *obj)
+{
+    if (obj == NULL)
+        return NULL;
+    return obj->data;
+}