From 8b4052ad6015aa9f54c9c824f28655f230d09d8d Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Tue, 10 Aug 2004 18:38:01 +0000 Subject: [PATCH] Move over to log_assert. Change usage of assert to log a critical error before actually asserting, so that we can tell this has happened from the logfile. --- armor.c | 8 ++++---- cleankey.c | 5 ++--- decodekey.c | 3 +-- keydb_db4.c | 9 ++++----- keyid.c | 7 +++---- keyindex.c | 1 - ll.c | 6 +++--- log.h | 12 ++++++++++++ mem.c | 16 ++++++++-------- merge.c | 7 +++---- parsekey.c | 11 +++++------ photoid.c | 7 +++---- 12 files changed, 48 insertions(+), 44 deletions(-) diff --git a/armor.c b/armor.c index ac1d23f..6d3fc13 100644 --- a/armor.c +++ b/armor.c @@ -6,11 +6,11 @@ * Copyright 2002 Project Purple */ -#include #include #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; diff --git a/cleankey.c b/cleankey.c index f3110cc..4d1ec1c 100644 --- a/cleankey.c +++ b/cleankey.c @@ -6,7 +6,6 @@ * Copyright 2004 Project Purple */ -#include #include #include #include @@ -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); diff --git a/decodekey.c b/decodekey.c index 723435a..efffad7 100644 --- a/decodekey.c +++ b/decodekey.c @@ -6,7 +6,6 @@ * Copyright 2002 Project Purple */ -#include #include #include #include @@ -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; diff --git a/keydb_db4.c b/keydb_db4.c index 04949d0..899cd87 100644 --- a/keydb_db4.c +++ b/keydb_db4.c @@ -6,7 +6,6 @@ * Copyright 2002-2004 Project Purple */ -#include #include #include #include @@ -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 66713d1..2bec710 100644 --- a/keyid.c +++ b/keyid.c @@ -8,7 +8,6 @@ #include -#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: diff --git a/keyindex.c b/keyindex.c index f81de95..2e3d2c6 100644 --- a/keyindex.c +++ b/keyindex.c @@ -6,7 +6,6 @@ * Copyright 2002 Project Purple */ -#include #include #include #include diff --git a/ll.c b/ll.c index 4d1ea4a..3545a9c 100644 --- a/ll.c +++ b/ll.c @@ -6,11 +6,11 @@ * Copyright 2000-2002 Project Purple */ -#include #include #include #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 ed2818f..818f5f2 100644 --- a/log.h +++ b/log.h @@ -9,6 +9,18 @@ #ifndef __LOG_H__ #define __LOG_H__ +#include + +#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 83ffa55..5ba9090 100644 --- a/mem.c +++ b/mem.c @@ -6,13 +6,13 @@ * Copyright 2002 Project Purple */ -#include #include #include #include #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 18882e9..d2d2beb 100644 --- a/merge.c +++ b/merge.c @@ -6,7 +6,6 @@ * Copyright 2002 Project Purple */ -#include #include #include #include @@ -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; diff --git a/parsekey.c b/parsekey.c index fb9cf83..687fd9b 100644 --- a/parsekey.c +++ b/parsekey.c @@ -6,7 +6,6 @@ * Copyright 2002 Project Purple */ -#include #include #include #include @@ -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) { diff --git a/photoid.c b/photoid.c index 2debf01..dd28753 100644 --- a/photoid.c +++ b/photoid.c @@ -6,7 +6,6 @@ * Copyright 2004 Project Purple */ -#include #include #include #include @@ -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; -- 2.39.5