From: Greg Hudson Date: Sun, 5 Jun 2011 22:05:04 +0000 (+0000) Subject: Remove static error table list in built-in com_err X-Git-Tag: krb5-1.10-alpha1~414 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=71125ee37ecc540fb60a6efbf4dac80468e1359e;p=krb5.git Remove static error table list in built-in com_err _et_list has been private to error_message.c since March 2004, and since nothing in that file ever added entries to it, it is always NULL. As it's not doing any good, get rid of it, and rename the dynamic error table list to "et_list", along with its type. Also remove some old lclint annotations. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@24947 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/util/et/error_message.c b/src/util/et/error_message.c index e3fc52d53..35d58f306 100644 --- a/src/util/et/error_message.c +++ b/src/util/et/error_message.c @@ -35,8 +35,7 @@ extern char const * const sys_errlist[]; extern const int sys_nerr; #endif -/*@null@*/ static struct et_list * _et_list = (struct et_list *) NULL; -/*@null@*//*@only@*/static struct dynamic_et_list * et_list_dynamic; +static struct et_list *et_list; static k5_mutex_t et_list_lock = K5_MUTEX_PARTIAL_INITIALIZER; static int terminated = 0; /* for debugging shlib fini sequence errors */ @@ -64,7 +63,7 @@ int com_err_initialize(void) void com_err_terminate(void) { - struct dynamic_et_list *e, *enext; + struct et_list *e, *enext; if (! INITIALIZER_RAN(com_err_initialize) || PROGRAM_EXITING()) { #ifdef SHOW_INITFINI_FUNCS printf("com_err_terminate: skipping\n"); @@ -78,7 +77,7 @@ void com_err_terminate(void) k5_mutex_destroy(&com_err_hook_lock); if (k5_mutex_lock(&et_list_lock) != 0) return; - for (e = et_list_dynamic; e; e = enext) { + for (e = et_list; e; e = enext) { enext = e->next; free(e); } @@ -113,12 +112,10 @@ get_thread_buffer () const char * KRB5_CALLCONV error_message(long code) -/*@modifies internalState@*/ { unsigned long offset; unsigned long l_offset; - struct et_list *et; - struct dynamic_et_list *det; + struct et_list *e; unsigned long table_num; int started = 0; unsigned int divisor = 100; @@ -165,23 +162,12 @@ error_message(long code) merr = k5_mutex_lock(&et_list_lock); if (merr) goto oops; - dprintf (("scanning static list for %x\n", table_num)); - for (et = _et_list; et != NULL; et = et->next) { - if (et->table == NULL) - continue; - dprintf (("\t%x = %s\n", et->table->base & ERRCODE_MAX, - et->table->msgs[0])); - if ((et->table->base & ERRCODE_MAX) == table_num) { - table = et->table; - goto found; - } - } - dprintf (("scanning dynamic list for %x\n", table_num)); - for (det = et_list_dynamic; det != NULL; det = det->next) { - dprintf (("\t%x = %s\n", det->table->base & ERRCODE_MAX, - det->table->msgs[0])); - if ((det->table->base & ERRCODE_MAX) == table_num) { - table = det->table; + dprintf(("scanning list for %x\n", table_num)); + for (e = et_list; e != NULL; e = e->next) { + dprintf(("\t%x = %s\n", e->table->base & ERRCODE_MAX, + e->table->msgs[0])); + if ((e->table->base & ERRCODE_MAX) == table_num) { + table = e->table; goto found; } } @@ -282,42 +268,35 @@ oops: return(cp1); } -/*@-incondefs@*/ /* _et_list is global on unix but not in header annotations */ errcode_t KRB5_CALLCONV -add_error_table(/*@dependent@*/ const struct error_table * et) -/*@modifies _et_list,et_list_dynamic@*/ -/*@=incondefs@*/ +add_error_table(const struct error_table *et) { - struct dynamic_et_list *del; + struct et_list *e; int merr; if (CALL_INIT_FUNCTION(com_err_initialize)) return 0; - del = (struct dynamic_et_list *)malloc(sizeof(struct dynamic_et_list)); - if (del == NULL) + e = malloc(sizeof(struct et_list)); + if (e == NULL) return ENOMEM; - del->table = et; + e->table = et; merr = k5_mutex_lock(&et_list_lock); if (merr) { - free(del); + free(e); return merr; } - del->next = et_list_dynamic; - et_list_dynamic = del; + e->next = et_list; + et_list = e; return k5_mutex_unlock(&et_list_lock); } -/*@-incondefs@*/ /* _et_list is global on unix but not in header annotations */ errcode_t KRB5_CALLCONV -remove_error_table(const struct error_table * et) -/*@modifies _et_list,et_list_dynamic@*/ -/*@=incondefs@*/ +remove_error_table(const struct error_table *et) { - struct dynamic_et_list **del; - struct et_list **el; + struct et_list **ep, *e; int merr; if (CALL_INIT_FUNCTION(com_err_initialize)) @@ -326,23 +305,15 @@ remove_error_table(const struct error_table * et) if (merr) return merr; - /* Remove the entry that matches the error table instance. Prefer dynamic - entries, but if there are none, check for a static one too. */ - for (del = &et_list_dynamic; *del; del = &(*del)->next) - if ((*del)->table == et) { - /*@only@*/ struct dynamic_et_list *old = *del; - *del = old->next; - free (old); - return k5_mutex_unlock(&et_list_lock); - } - for (el = &_et_list; *el; el = &(*el)->next) - if ((*el)->table == et) { - struct et_list *old = *el; - *el = old->next; - old->next = NULL; - old->table = NULL; + /* Remove the entry that matches the error table instance. */ + for (ep = &et_list; *ep; ep = &(*ep)->next) { + if ((*ep)->table == et) { + e = *ep; + *ep = e->next; + free(e); return k5_mutex_unlock(&et_list_lock); } + } k5_mutex_unlock(&et_list_lock); return ENOENT; } diff --git a/src/util/et/error_table.h b/src/util/et/error_table.h index ce7f4ba8b..c458b048a 100644 --- a/src/util/et/error_table.h +++ b/src/util/et/error_table.h @@ -13,28 +13,20 @@ #define ET_EBUFSIZ 1024 struct et_list { - /*@dependent@*//*@null@*/ struct et_list *next; - /*@dependent@*//*@null@*/ const struct error_table *table; -}; - -struct dynamic_et_list { - /*@only@*//*@null@*/ struct dynamic_et_list *next; - /*@dependent@*/ const struct error_table *table; + struct et_list *next; + const struct error_table *table; }; #define ERRCODE_RANGE 8 /* # of bits to shift table number */ #define BITS_PER_CHAR 6 /* # bits to shift per character in name */ #define ERRCODE_MAX 0xFFFFFFFFUL /* Mask for maximum error table */ -extern /*@observer@*/ const char *error_table_name (unsigned long) - /*@modifies internalState@*/; -extern const char *error_table_name_r (unsigned long, - /*@out@*/ /*@returned@*/ char *outbuf) - /*@modifies outbuf@*/; +const char *error_table_name(unsigned long); +const char *error_table_name_r(unsigned long, char *outbuf); #include "k5-thread.h" extern k5_mutex_t com_err_hook_lock; -extern int com_err_finish_init(void); +int com_err_finish_init(void); #define _ET_H #endif