]> git.sommitrealweird.co.uk Git - onak.git/commitdiff
Move over to log_assert.
authorJonathan McDowell <noodles@earth.li>
Tue, 10 Aug 2004 18:38:01 +0000 (18:38 +0000)
committerJonathan McDowell <noodles@earth.li>
Tue, 10 Aug 2004 18:38:01 +0000 (18:38 +0000)
Change usage of assert to log a critical error before actually asserting,
so that we can tell this has happened from the logfile.

12 files changed:
armor.c
cleankey.c
decodekey.c
keydb_db4.c
keyid.c
keyindex.c
ll.c
log.h
mem.c
merge.c
parsekey.c
photoid.c

diff --git a/armor.c b/armor.c
index ac1d23f44d1696ede71258dafde24f6b4086061d..6d3fc138f6bee1445f9ac9fea4a0f20139723468 100644 (file)
--- a/armor.c
+++ b/armor.c
@@ -6,11 +6,11 @@
  * Copyright 2002 Project Purple
  */
 
-#include <assert.h>
 #include <stdlib.h>
 
 #include "armor.h"
 #include "keystructs.h"
+#include "log.h"
 #include "onak-conf.h"
 #include "parsekey.h"
 
@@ -34,7 +34,7 @@ static unsigned char encode64(unsigned char c) {
        } else if (c == 63) {
                c = '/';
        } else {
-               assert(c < 64);
+               log_assert(c < 64);
        }
 
        return c;
@@ -142,7 +142,7 @@ static int armor_putchar_int(void *ctx, unsigned char c)
        unsigned char t;
        int i;
 
-       assert(ctx != NULL);
+       log_assert(ctx != NULL);
        state = (struct armor_context *) ctx;
 
        switch (state->curoctet++) {
@@ -243,7 +243,7 @@ static int dearmor_getchar(void *ctx, unsigned char *c)
        unsigned char tmpc;
        int i;
 
-       assert(ctx != NULL);
+       log_assert(ctx != NULL);
        state = (struct dearmor_context *) ctx;
        *c = 0;
        
index f3110cc8efba3ccecb05e05deb97d69b1ac2bf49..4d1ec1c890424f347281f52655bbe31c248ce50c 100644 (file)
@@ -6,7 +6,6 @@
  * Copyright 2004 Project Purple
  */
 
-#include <assert.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -31,7 +30,7 @@ int dedupuids(struct openpgp_publickey *key)
        struct openpgp_signedpacket_list *tmp = NULL;
        int                               merged = 0;
 
-       assert(key != NULL);
+       log_assert(key != NULL);
        curuid = key->uids;
        while (curuid != NULL) {
                dup = find_signed_packet(curuid->next, curuid->packet);
@@ -48,7 +47,7 @@ int dedupuids(struct openpgp_publickey *key)
                        while (tmp != NULL && tmp->next != dup) {
                                tmp = tmp->next;
                        }
-                       assert(tmp != NULL);
+                       log_assert(tmp != NULL);
                        tmp->next = dup->next;
                        dup->next = NULL;
                        free_signedpacket_list(dup);
index 723435ad8513335f0aea516f82ecd90c8775f99e..efffad7d7863a7e310647113801fb21ba545c22f 100644 (file)
@@ -6,7 +6,6 @@
  * Copyright 2002 Project Purple
  */
 
-#include <assert.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -35,7 +34,7 @@ int parse_subpackets(unsigned char *data, uint64_t *keyid)
        int length = 0;
        int packetlen = 0;
 
-       assert(data != NULL);
+       log_assert(data != NULL);
 
        length = (data[0] << 8) + data[1] + 2;
 
index 04949d000ce90dd48a37401f12cf15855434530f..899cd878467735ae8a57d5543a773c200334aa6d 100644 (file)
@@ -6,7 +6,6 @@
  * Copyright 2002-2004 Project Purple
  */
 
-#include <assert.h>
 #include <sys/types.h>
 #include <sys/uio.h>
 #include <ctype.h>
@@ -249,8 +248,8 @@ bool starttrans(void)
 {
        int ret;
 
-       assert(dbenv != NULL);
-       assert(txn == NULL);
+       log_assert(dbenv != NULL);
+       log_assert(txn == NULL);
 
        ret = dbenv->txn_begin(dbenv,
                NULL, /* No parent transaction */
@@ -275,8 +274,8 @@ void endtrans(void)
 {
        int ret;
 
-       assert(dbenv != NULL);
-       assert(txn != NULL);
+       log_assert(dbenv != NULL);
+       log_assert(txn != NULL);
 
        ret = txn->commit(txn,
                0);
diff --git a/keyid.c b/keyid.c
index 66713d1a11765e5441108a342d69e7f80d96afd5..2bec710026f85a92fe4ce6f8547700d6b998f3c1 100644 (file)
--- a/keyid.c
+++ b/keyid.c
@@ -8,7 +8,6 @@
 
 #include <sys/types.h>
 
-#include "assert.h"
 #include "keyid.h"
 #include "keystructs.h"
 #include "log.h"
@@ -44,8 +43,8 @@ unsigned char *get_fingerprint(struct openpgp_packet *packet,
        unsigned char c;
        size_t         modlen, explen;
 
-       assert(fingerprint != NULL);
-       assert(len != NULL);
+       log_assert(fingerprint != NULL);
+       log_assert(len != NULL);
 
        *len = 0;
 
@@ -110,7 +109,7 @@ uint64_t get_packetid(struct openpgp_packet *packet)
        size_t          length = 0;
        unsigned char   buff[20];
 
-       assert(packet != NULL);
+       log_assert(packet != NULL);
 
        switch (packet->data[0]) {
        case 2:
index f81de957b9e521bdabf98abe050feeb93597d217..2e3d2c66f77b7f893df3ed74d71ecf0ec030c535 100644 (file)
@@ -6,7 +6,6 @@
  * Copyright 2002 Project Purple
  */
 
-#include <assert.h>
 #include <inttypes.h>
 #include <stdbool.h>
 #include <stdio.h>
diff --git a/ll.c b/ll.c
index 4d1ea4a71f63d054b217bb791be00bdc3f3efc95..3545a9c48232221a7ea9ffedfa7b69f3dd98de83 100644 (file)
--- a/ll.c
+++ b/ll.c
@@ -6,11 +6,11 @@
  * Copyright 2000-2002 Project Purple
  */
 
-#include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
 
 #include "ll.h"
+#include "log.h"
 
 struct ll *lladd(struct ll *curll, void *object)
 {
@@ -34,7 +34,7 @@ struct ll *lldel(struct ll *curll, void *object,
        struct ll *cur = NULL;
        struct ll *old = NULL;
 
-       assert(objectcmp != NULL);
+       log_assert(objectcmp != NULL);
 
        cur = curll;
        if (cur == NULL) {
@@ -61,7 +61,7 @@ struct ll *llfind(struct ll *curll, void *object,
 {
        struct ll *cur;
 
-       assert(objectcmp != NULL);
+       log_assert(objectcmp != NULL);
 
        cur = curll;
        while (cur != NULL && (*objectcmp)(cur->object, object)) {
diff --git a/log.h b/log.h
index ed2818f29e8b4b3d929cb2c6b8b63d2439b7e263..818f5f2d96ef61162080bfb79a028d25c3f640f8 100644 (file)
--- a/log.h
+++ b/log.h
@@ -9,6 +9,18 @@
 #ifndef __LOG_H__
 #define __LOG_H__
 
+#include <assert.h>
+
+#define log_assert(expr) \
+       if (!(expr)) { \
+               logthing(LOGTHING_CRITICAL, \
+                       "Assertion %s failed in %s, line %d", \
+                       #expr, \
+                       __FILE__, \
+                       __LINE__); \
+       } \
+       assert(expr)
+
 /*
  *     loglevels - levels of severity for a log entry
  *
diff --git a/mem.c b/mem.c
index 83ffa55375e5713477d4d68dacadf59a6d5e73e0..5ba9090b08cd52b507b9cb77ca02865004481071 100644 (file)
--- a/mem.c
+++ b/mem.c
@@ -6,13 +6,13 @@
  * Copyright 2002 Project Purple
  */
 
-#include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
 #include "keystructs.h"
 #include "ll.h"
+#include "log.h"
 #include "mem.h"
 
 /**
@@ -27,7 +27,7 @@ struct openpgp_packet *packet_dup(struct openpgp_packet *packet)
 {
        struct openpgp_packet *newpacket = NULL;
 
-       assert(packet != NULL);
+       log_assert(packet != NULL);
 
        newpacket = malloc(sizeof (struct openpgp_packet));
        if (newpacket != NULL) {
@@ -59,8 +59,8 @@ void packet_list_add(struct openpgp_packet_list **list,
                struct openpgp_packet_list **list_end,
                struct openpgp_packet_list *packet_list)
 {
-       assert(list != NULL);
-       assert(list_end != NULL);
+       log_assert(list != NULL);
+       log_assert(list_end != NULL);
 
        for (; packet_list != NULL; packet_list = packet_list->next) {
                ADD_PACKET_TO_LIST((*list_end),
@@ -81,7 +81,7 @@ void packet_list_add(struct openpgp_packet_list **list,
  *     including the data part.
  */
 void free_packet(struct openpgp_packet *packet) {
-       assert(packet != NULL);
+       log_assert(packet != NULL);
 
        if (packet->data != NULL) {
                free(packet->data);
@@ -100,7 +100,7 @@ void free_packet(struct openpgp_packet *packet) {
 void free_packet_list(struct openpgp_packet_list *packet_list) {
        struct openpgp_packet_list *nextpacket = NULL;
 
-       assert(packet_list != NULL);
+       log_assert(packet_list != NULL);
 
        while (packet_list != NULL) {
                nextpacket = packet_list->next;
@@ -123,7 +123,7 @@ void free_signedpacket_list(
                struct openpgp_signedpacket_list *signedpacket_list) {
        struct openpgp_signedpacket_list *nextpacket = NULL;
 
-       assert(signedpacket_list != NULL);
+       log_assert(signedpacket_list != NULL);
 
        while (signedpacket_list != NULL) {
                nextpacket = signedpacket_list->next;
@@ -148,7 +148,7 @@ void free_signedpacket_list(
 void free_publickey(struct openpgp_publickey *key) {
        struct openpgp_publickey *nextkey = NULL;
 
-       assert(key != NULL);
+       log_assert(key != NULL);
 
        while (key != NULL) {
                nextkey = key->next;
diff --git a/merge.c b/merge.c
index 18882e92b92251f7c3f83f75938117f20a579857..d2d2beb1ace4f87471cdb5b9396323f9fb3389f8 100644 (file)
--- a/merge.c
+++ b/merge.c
@@ -6,7 +6,6 @@
  * Copyright 2002 Project Purple
  */
 
-#include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -174,7 +173,7 @@ int merge_packet_sigs(struct openpgp_signedpacket_list *old,
        struct openpgp_packet_list      *curpacket = NULL;
        struct openpgp_packet_list      *nextpacket = NULL;
 
-       assert(compare_packets(old->packet, new->packet));
+       log_assert(compare_packets(old->packet, new->packet));
 
        curpacket = new->sigs;
        while (curpacket != NULL) {
@@ -194,7 +193,7 @@ int merge_packet_sigs(struct openpgp_signedpacket_list *old,
                        if (lastpacket != NULL) {
                                lastpacket->next = curpacket->next;
                        } else {
-                               assert(curpacket == new->sigs);
+                               log_assert(curpacket == new->sigs);
                                new->sigs = curpacket->next;
                        }
                        curpacket->next = NULL;
@@ -319,7 +318,7 @@ int merge_keys(struct openpgp_publickey *a, struct openpgp_publickey *b)
                                if (lastpacket != NULL) {
                                        lastpacket->next = curpacket->next;
                                } else {
-                                       assert(curpacket == b->revocations);
+                                       log_assert(curpacket == b->revocations);
                                        b->revocations = curpacket->next;
                                }
                                curpacket->next = NULL;
index fb9cf83e25b0ce33c0a0a4b2e454cebd04c179d6..687fd9bd8612c6f9a3cd2c41af96e9269368a620 100644 (file)
@@ -6,7 +6,6 @@
  * Copyright 2002 Project Purple
  */
 
-#include <assert.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -52,7 +51,7 @@ int parse_keys(struct openpgp_packet_list *packets,
                         * key (it should be a revocation), to the current UID
                         * or the current subkey.
                         */
-                       assert(curkey != NULL);
+                       log_assert(curkey != NULL);
                        if (curkey->subkeys != NULL) {
                                ADD_PACKET_TO_LIST_END(curkey->last_subkey,
                                        sig,
@@ -88,8 +87,8 @@ int parse_keys(struct openpgp_packet_list *packets,
                        /*
                         * It's a UID packet (or a photo id, which is similar).
                         */
-                       assert(curkey != NULL);
-                       assert(curkey->subkeys == NULL);
+                       log_assert(curkey != NULL);
+                       log_assert(curkey->subkeys == NULL);
                        ADD_PACKET_TO_LIST_END(curkey,
                                uid,
                                packet_dup(packets->packet));
@@ -98,7 +97,7 @@ int parse_keys(struct openpgp_packet_list *packets,
                        /*
                         * It's a subkey packet.
                         */
-                       assert(curkey != NULL);
+                       log_assert(curkey != NULL);
                        ADD_PACKET_TO_LIST_END(curkey,
                                subkey,
                                packet_dup(packets->packet));
@@ -164,7 +163,7 @@ int read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count,
        int                              keys = 0;
        bool                             inpacket = false;
 
-       assert(packets != NULL);
+       log_assert(packets != NULL);
        curpacket = *packets;
        if (curpacket != NULL) {
                while (curpacket->next != NULL) {
index 2debf011bb3692db76ae2cfa877ea3efc71dba0e..dd28753e49f6dfd4ef6e82b7b395e87069d535e9 100644 (file)
--- a/photoid.c
+++ b/photoid.c
@@ -6,7 +6,6 @@
  * Copyright 2004 Project Purple
  */
 
-#include <assert.h>
 #include <inttypes.h>
 #include <stdbool.h>
 #include <stdio.h>
@@ -37,9 +36,9 @@ int getphoto(struct openpgp_publickey *key, int index, unsigned char **photo,
        int                               i = 0;
        int                               j = 0;
 
-       assert(key != NULL);
-       assert(photo != NULL);
-       assert(length != NULL);
+       log_assert(key != NULL);
+       log_assert(photo != NULL);
+       log_assert(length != NULL);
 
        *photo = NULL;