# HG changeset patch # User Will Thompson # Date 1192364360 0 # Node ID 5a3242b676ada5132969e22ea59a17c399021e1a # Parent be75cb19f5487fc0956d03d5809cc3ff84895e0b 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. diff -r be75cb19f548 -r 5a3242b676ad libpurple/connection.c --- 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"); diff -r be75cb19f548 -r 5a3242b676ad libpurple/connection.h --- 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 #include "account.h"