From: scipio Date: Tue, 10 Apr 2007 22:15:39 +0000 (+0000) Subject: Fixed memory bug. X-Git-Tag: tinyos/2.0.1~80 X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=commitdiff_plain;ds=sidebyside;h=fad51d10a27d4b4ebe2772950915d52fe4345482;p=tinyos-2.x.git Fixed memory bug. --- diff --git a/tos/lib/tossim/hashtable.c b/tos/lib/tossim/hashtable.c index 8a4e19ae..d04262aa 100644 --- a/tos/lib/tossim/hashtable.c +++ b/tos/lib/tossim/hashtable.c @@ -24,6 +24,8 @@ static const unsigned int primes[] = { const unsigned int prime_table_length = sizeof(primes)/sizeof(primes[0]); const float max_load_factor = 0.65; +#define BAD_RECORD (0xc693748) + /*****************************************************************************/ struct hashtable * create_hashtable(unsigned int minsize, @@ -133,6 +135,8 @@ hashtable_count(struct hashtable *h) } /*****************************************************************************/ +int entered = 0; + int hashtable_insert(struct hashtable *h, void *k, void *v) { @@ -147,12 +151,30 @@ hashtable_insert(struct hashtable *h, void *k, void *v) * element may be ok. Next time we insert, we'll try expanding again.*/ hashtable_expand(h); } + if (entered) { + struct entry* eTest = (struct entry*)BAD_RECORD; + if (eTest->v == (void*)0x3f800000) { + //printf("Insert CORRUPT\n"); + } + } e = (struct entry *)malloc(sizeof(struct entry)); if (NULL == e) { --(h->entrycount); return 0; } /*oom*/ + if (e == (void*)BAD_RECORD) { + entered = 1; + //printf("Allocated 0x%x\n", e); + } e->h = hash(h,k); + if (e->h == 4101970376) { + int i; + //printf("Inserting key with suspect hashvalue:\n "); + for (i = 0; i < 20; i++) { + //printf("%hhi ", ((char*)k)[i]); + } + //printf("\n"); + } tindex = indexFor(h->tablelength,e->h); - if (v == (void*)0x477fed00) { - printf("CORRUPT\n"); + if (v == (void*)0x3f800000) { + //printf("Insert post CORRUPT\n"); } e->k = k; e->v = v; @@ -170,15 +192,21 @@ hashtable_search(struct hashtable *h, void *k) hashvalue = hash(h,k); tindex = indexFor(h->tablelength,hashvalue); e = h->table[tindex]; - if (hashvalue == 1741511095) { - int i = 5; + if (entered) { + struct entry* eTest = (struct entry*)BAD_RECORD; + if (eTest->v == (void*)0x3f800000) { + //printf("Search CORRUPT\n"); + } } while (NULL != e) { /* Check hash value to short circuit heavier comparison */ if ((hashvalue == e->h) && (h->eqfn(k, e->k))) { - if ((int)e->v == 0x477fed00) { - printf("ALARM\n"); + if (hashvalue == 4101970376) { + //printf("Retreiving key with suspect hhashvalue: 0x%x -> 0x%x\n", e, e->v); + } + if ((int)e->v == 0x3f800000) { + //printf("ALARM: 0x%x has 0x%x\n", e, e->v); } return e->v; } diff --git a/tos/lib/tossim/randomlib.c b/tos/lib/tossim/randomlib.c index 9d52c32c..c50ebef1 100644 --- a/tos/lib/tossim/randomlib.c +++ b/tos/lib/tossim/randomlib.c @@ -36,7 +36,7 @@ */ /* Globals */ -static double u[97],c,cd,cm; +static double randU[97], randC, randCD, randCM; static int i97,j97; static int test = FALSE; @@ -85,12 +85,12 @@ void RandomInitialise(int ij,int kl) s += t; t *= 0.5; } - u[ii] = s; + randU[ii] = s; } - c = 362436.0 / 16777216.0; - cd = 7654321.0 / 16777216.0; - cm = 16777213.0 / 16777216.0; + randC = 362436.0 / 16777216.0; + randCD = 7654321.0 / 16777216.0; + randCM = 16777213.0 / 16777216.0; i97 = 97; j97 = 33; test = TRUE; @@ -116,20 +116,20 @@ double RandomUniform(void) RandomInitialise(seed1,seed2); #endif } - uni = u[i97-1] - u[j97-1]; + uni = randU[i97-1] - randU[j97-1]; if (uni <= 0.0) uni++; - u[i97-1] = uni; + randU[i97-1] = uni; i97--; if (i97 == 0) i97 = 97; j97--; if (j97 == 0) j97 = 97; - c -= cd; - if (c < 0.0) - c += cm; - uni -= c; + randC -= randCD; + if (randC < 0.0) + randC += randCM; + uni -= randC; if (uni < 0.0) uni++; diff --git a/tos/lib/tossim/sim_noise.c b/tos/lib/tossim/sim_noise.c index 6a5dca74..eb9784d0 100644 --- a/tos/lib/tossim/sim_noise.c +++ b/tos/lib/tossim/sim_noise.c @@ -98,6 +98,9 @@ void sim_noise_trace_add(uint16_t node_id, char noiseVal)__attribute__ ((C, spon uint8_t search_bin_num(char noise)__attribute__ ((C, spontaneous)) { uint8_t bin; + if (noise > NOISE_MAX || noise < NOISE_MIN) { + noise = NOISE_MIN; + } bin = (noise-NOISE_MIN)/NOISE_QUANTIZE_INTERVAL + 1; return bin; } @@ -242,6 +245,9 @@ void makePmfDistr(uint16_t node_id)__attribute__ ((C, spontaneous)) sim_noise_dist(node_id); arrangeKey(node_id); for(i = NOISE_HISTORY; i < noiseData[node_id].noiseTraceIndex; i++) { + if (i >= 196605) { + int foo = 7; + } if (i == NOISE_HISTORY) { printf("Inserting first element.\n"); } @@ -330,6 +336,11 @@ char sim_noise_generate(uint16_t node_id, uint32_t cur_t)__attribute__ ((C, spon prev_t = noiseData[node_id].noiseGenTime; + if (noiseData[node_id].generated == 0) { + dbgerror("TOSSIM", "Tried to generate noise from an uninitialized radio model of node %hu.\n", node_id); + return 127; + } + if ( (0<= cur_t) && (cur_t < NOISE_HISTORY) ) { noiseData[node_id].noiseGenTime = cur_t; noiseData[node_id].key[cur_t] = search_bin_num(noiseData[node_id].noiseTrace[cur_t]); @@ -384,6 +395,7 @@ void makeNoiseModel(uint16_t node_id)__attribute__ ((C, spontaneous)) { sim_noise_add(node_id, noiseData[node_id].noiseTrace[i+1]); arrangeKey(node_id); } + noiseData[node_id].generated = 1; } diff --git a/tos/lib/tossim/sim_noise.h b/tos/lib/tossim/sim_noise.h index 078c5842..a46aea9b 100644 --- a/tos/lib/tossim/sim_noise.h +++ b/tos/lib/tossim/sim_noise.h @@ -41,9 +41,9 @@ extern "C" { #endif enum { - NOISE_MIN = -100, - NOISE_MAX = -30, - NOISE_MIN_QUANTIZE = -100, + NOISE_MIN = -115, + NOISE_MAX = -5, + NOISE_MIN_QUANTIZE = -115, NOISE_QUANTIZE_INTERVAL = 5, NOISE_BIN_SIZE = (NOISE_MAX - NOISE_MIN)/NOISE_QUANTIZE_INTERVAL, NOISE_HISTORY = 20, @@ -70,6 +70,7 @@ typedef struct sim_noise_node_t { char* noiseTrace; uint32_t noiseTraceLen; uint32_t noiseTraceIndex; + bool generated; } sim_noise_node_t; void sim_noise_init();