From b531bdd1bce4d6dcfc2be551c23eab97e93029c5 Mon Sep 17 00:00:00 2001 From: Per Cederqvist <ceder@lysator.liu.se> Date: Thu, 5 Sep 1991 08:25:58 +0000 Subject: [PATCH] get_{pers,conf,text}_node: returnera NULL om f|r h|gt nummer beg{rs. mark_conference_as_changed: s{tt {ven nice och type i small_conf_arr. N}gra defensiva extrakontroller. --- src/server/simple-cache.c | 72 +++++++++++++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 11 deletions(-) diff --git a/src/server/simple-cache.c b/src/server/simple-cache.c index 50498ec77..6da340180 100644 --- a/src/server/simple-cache.c +++ b/src/server/simple-cache.c @@ -9,7 +9,7 @@ * New save algorithm by ceder. */ -static char *rcsid = "$Id: simple-cache.c,v 0.13 1991/08/30 03:35:52 ceder Exp $"; +static char *rcsid = "$Id: simple-cache.c,v 0.14 1991/09/05 08:25:58 ceder Exp $"; @@ -184,6 +184,9 @@ conf_set_mru(Conf_no conf_no) static Cache_node * get_pers_node(Pers_no pers_no) { + if ( pers_no >= next_free_num ) + return NULL; + return get_cache_node(pers_mcb, pers_no); } @@ -208,12 +211,18 @@ unlink_pers_lru (Cache_node *node) static Cache_node * get_conf_node(Conf_no conf_no) { + if ( conf_no >= next_free_num ) + return NULL; + return get_cache_node(conf_mcb, conf_no); } static Cache_node * get_text_node(Text_no text_no) { + if ( text_no >= next_text_num ) + return NULL; + return get_cache_node(text_mcb, text_no); } @@ -287,11 +296,23 @@ mark_person_as_changed(Pers_no pers_no) pers_set_mru( pers_no ); } +/* + * Mark the conference as dirty, so that it will be written to + * the disk. + * + * Also update all fields in the Small_conf except then name, so that + * they are always current. + * + * NOTE: You must call cached_change_name when the name changes. + * It is not necessary to call cached_change_name after + * cached_create_conf. + */ void mark_conference_as_changed(Conf_no conf_no) { Cache_node *node; + Conference *conf_c; node = get_conf_node (conf_no); @@ -301,9 +322,14 @@ mark_conference_as_changed(Conf_no conf_no) node->s.dirty = 1; conf_set_mru( conf_no ); + + conf_c = (Conference *) node->ptr; + small_conf_arr[ conf_no ]->highest_local_no - = (((Conference *)node->ptr)->texts.first_local_no - 1 - + ((Conference *)node->ptr)->texts.no_of_texts ); + = (conf_c->texts.first_local_no - 1 + conf_c->texts.no_of_texts ); + + small_conf_arr[ conf_no ]->nice = conf_c->nice; + small_conf_arr[ conf_no ]->type = conf_c->type; } void @@ -377,10 +403,15 @@ cached_get_person_stat( Pers_no person ) return NULL; } + if ( person >= next_free_num ) + { + kom_errno = KOM_UNDEF_PERS; + return NULL; + } + node = get_pers_node (person); - if ( person >= next_free_num || node == NULL - || node->s.exists == 0 ) + if ( node == NULL || node->s.exists == 0 ) { kom_errno = KOM_UNDEF_PERS; return NULL; @@ -440,7 +471,12 @@ alloc_small_conf(void) } -extern Conf_no /* Also cache the name */ +/* + * Create a conference. + * + * Set up a Conference and cache the name in the small_conf_array. + */ +extern Conf_no cached_create_conf (String name) { Conference * conf_c; @@ -494,9 +530,15 @@ cached_delete_conf( Conf_no conf ) return FAILURE; } + if ( conf >= next_free_num ) + { + kom_errno = KOM_UNDEF_CONF; + return FAILURE; + } + node = get_conf_node (conf); - if ( conf >= next_free_num || node == NULL || node->s.exists == 0 ) + if ( node == NULL || node->s.exists == 0 ) { kom_errno = KOM_UNDEF_CONF; return FAILURE; @@ -524,6 +566,14 @@ cached_delete_person(Pers_no pers) return FAILURE; } + if ( pers >= next_free_num ) + { + log("cached_delete_person(%lu): next_free_num == %lu\n", + (u_long)pers, (u_long)next_free_num); + kom_errno = KOM_UNDEF_PERS; + return FAILURE; + } + node = get_pers_node (pers); if ( pers >= next_free_num || node == NULL || node->s.exists == 0 ) @@ -535,8 +585,8 @@ cached_delete_person(Pers_no pers) } if ( node->lock_cnt > 0 ) - log("cached_delete_pers(%d): lock_cnt === %d\n", - pers, node->lock_cnt); + log("cached_delete_pers(%lu): lock_cnt === %lu\n", + (u_long)pers, (u_long)node->lock_cnt); free_person (node->ptr); node->ptr = NULL; @@ -728,7 +778,7 @@ cached_get_text_stat( Text_no text ) /* * The text is set up with an empty misc-field. The misc field is - * than initialized by create_text. + * then initialized by create_text. */ extern Text_no @@ -905,7 +955,7 @@ cached_unlock_person(Pers_no pers_no) } -/* Lock a conf struct in memory. Increase a referenc count. */ +/* Lock a conf struct in memory. Increase a reference count. */ void cached_lock_conf(Conf_no conf_no) { -- GitLab