Mercurial > pidgin
changeset 21357:5a3242b676ad
rlaager suggested using the last element of the PurpleDisconnectReason enum
for sanity checking, which sidesteps the "should NUM_REASONS be in or out of
the enum?" problem.
author | Will Thompson <will.thompson@collabora.co.uk> |
---|---|
date | Sun, 14 Oct 2007 12:19:20 +0000 |
parents | be75cb19f548 |
children | ba41f2a60253 |
files | libpurple/connection.c libpurple/connection.h |
diffstat | 2 files changed, 14 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/connection.c Sat Oct 13 00:23:52 2007 +0000 +++ b/libpurple/connection.c Sun Oct 14 12:19:20 2007 +0000 @@ -508,7 +508,16 @@ PurpleConnectionUiOps *ops; g_return_if_fail(gc != NULL); - g_return_if_fail(reason < PURPLE_NUM_REASONS); + /* This sanity check relies on PURPLE_REASON_OTHER_ERROR being the + * last member of the PurpleDisconnectReason enum in connection.h; if + * other reasons are added after it, this check should be updated. + */ + if (reason > PURPLE_REASON_OTHER_ERROR) { + purple_debug_error("connection", + "purple_connection_error_reason: reason %u isn't a " + "valid reason\n", reason); + reason = PURPLE_REASON_OTHER_ERROR; + } if (description == NULL) { purple_debug_error("connection", "purple_connection_error_reason: check `description != NULL' failed\n");
--- a/libpurple/connection.h Sat Oct 13 00:23:52 2007 +0000 +++ b/libpurple/connection.h Sun Oct 14 12:19:20 2007 +0000 @@ -119,12 +119,13 @@ /** Some other error occured which fits into none of the other * categories. */ + /* purple_connection_error_reason() in connection.c uses the fact that + * this is the last member of the enum when sanity-checking; if other + * reasons are added after it, the check must be updated. + */ PURPLE_REASON_OTHER_ERROR = 15 } PurpleDisconnectReason; -/** 1 more than the value of the last #PurpleDisconnectReason. */ -#define PURPLE_NUM_REASONS 16 - #include <time.h> #include "account.h"