[Tinyos-2-commits] CVS: tinyos-2.x/tos/lib/tossim hashtable.c, 1.3, 1.4 randomlib.c, 1.1, 1.2 sim_noise.c, 1.4, 1.5 sim_noise.h, 1.3, 1.4

Phil Levis scipio at users.sourceforge.net
Tue Apr 10 15:15:41 PDT 2007


Update of /cvsroot/tinyos/tinyos-2.x/tos/lib/tossim
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv2719

Modified Files:
	hashtable.c randomlib.c sim_noise.c sim_noise.h 
Log Message:
Fixed memory bug.


Index: hashtable.c
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/tossim/hashtable.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** hashtable.c	1 Apr 2007 00:29:34 -0000	1.3
--- hashtable.c	10 Apr 2007 22:15:39 -0000	1.4
***************
*** 25,28 ****
--- 25,30 ----
  const float max_load_factor = 0.65;
  
+ #define BAD_RECORD (0xc693748)
+ 
  /*****************************************************************************/
  struct hashtable *
***************
*** 134,137 ****
--- 136,141 ----
  
  /*****************************************************************************/
+ int entered = 0;
+ 
  int
  hashtable_insert(struct hashtable *h, void *k, void *v)
***************
*** 148,157 ****
          hashtable_expand(h);
      }
      e = (struct entry *)malloc(sizeof(struct entry));
      if (NULL == e) { --(h->entrycount); return 0; } /*oom*/
      e->h = hash(h,k);
      tindex = indexFor(h->tablelength,e->h);
!     if (v == (void*)0x477fed00) {
!       printf("CORRUPT\n");
      }
      e->k = k;
--- 152,179 ----
          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*)0x3f800000) {
!       //printf("Insert post CORRUPT\n");
      }
      e->k = k;
***************
*** 171,176 ****
      tindex = indexFor(h->tablelength,hashvalue);
      e = h->table[tindex];
!     if (hashvalue == 1741511095) {
!       int i = 5;
      }
      while (NULL != e)
--- 193,201 ----
      tindex = indexFor(h->tablelength,hashvalue);
      e = h->table[tindex];
!     if (entered) {
!       struct entry* eTest = (struct entry*)BAD_RECORD;
!       if (eTest->v == (void*)0x3f800000) {
! 	//printf("Search CORRUPT\n");
!       }
      }
      while (NULL != e)
***************
*** 178,183 ****
          /* 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");
  	}
  	return e->v;
--- 203,211 ----
          /* Check hash value to short circuit heavier comparison */
        if ((hashvalue == e->h) && (h->eqfn(k, e->k))) {
! 	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;

Index: randomlib.c
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/tossim/randomlib.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** randomlib.c	1 Apr 2007 00:29:34 -0000	1.1
--- randomlib.c	10 Apr 2007 22:15:39 -0000	1.2
***************
*** 37,41 ****
  
  /* Globals */
! static double u[97],c,cd,cm;
  static int i97,j97;
  static int test = FALSE;
--- 37,41 ----
  
  /* Globals */
! static double randU[97], randC, randCD, randCM;
  static int i97,j97;
  static int test = FALSE;
***************
*** 86,95 ****
           t *= 0.5;
        }
!       u[ii] = s;
     }
  
!    c    = 362436.0 / 16777216.0;
!    cd   = 7654321.0 / 16777216.0;
!    cm   = 16777213.0 / 16777216.0;
     i97  = 97;
     j97  = 33;
--- 86,95 ----
           t *= 0.5;
        }
!       randU[ii] = s;
     }
  
!    randC    = 362436.0 / 16777216.0;
!    randCD   = 7654321.0 / 16777216.0;
!    randCM   = 16777213.0 / 16777216.0;
     i97  = 97;
     j97  = 33;
***************
*** 117,124 ****
  #endif
  	}
!    uni = u[i97-1] - u[j97-1];
     if (uni <= 0.0)
        uni++;
!    u[i97-1] = uni;
     i97--;
     if (i97 == 0)
--- 117,124 ----
  #endif
  	}
!    uni = randU[i97-1] - randU[j97-1];
     if (uni <= 0.0)
        uni++;
!    randU[i97-1] = uni;
     i97--;
     if (i97 == 0)
***************
*** 127,134 ****
     if (j97 == 0)
        j97 = 97;
!    c -= cd;
!    if (c < 0.0)
!       c += cm;
!    uni -= c;
     if (uni < 0.0)
        uni++;
--- 127,134 ----
     if (j97 == 0)
        j97 = 97;
!    randC -= randCD;
!    if (randC < 0.0)
!       randC += randCM;
!    uni -= randC;
     if (uni < 0.0)
        uni++;

Index: sim_noise.c
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/tossim/sim_noise.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** sim_noise.c	1 Apr 2007 00:52:10 -0000	1.4
--- sim_noise.c	10 Apr 2007 22:15:39 -0000	1.5
***************
*** 99,102 ****
--- 99,105 ----
  {
    uint8_t bin;
+   if (noise > NOISE_MAX || noise < NOISE_MIN) {
+     noise = NOISE_MIN;
+   }
    bin = (noise-NOISE_MIN)/NOISE_QUANTIZE_INTERVAL + 1;
    return bin;
***************
*** 243,246 ****
--- 246,252 ----
    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");
***************
*** 331,334 ****
--- 337,345 ----
    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;
***************
*** 385,388 ****
--- 396,400 ----
      arrangeKey(node_id);
    }
+   noiseData[node_id].generated = 1;
  }
  

Index: sim_noise.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/tossim/sim_noise.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** sim_noise.h	1 Apr 2007 00:52:10 -0000	1.3
--- sim_noise.h	10 Apr 2007 22:15:39 -0000	1.4
***************
*** 42,48 ****
  
  enum {
!   NOISE_MIN = -100,
!   NOISE_MAX = -30,
!   NOISE_MIN_QUANTIZE = -100,
    NOISE_QUANTIZE_INTERVAL = 5,
    NOISE_BIN_SIZE = (NOISE_MAX - NOISE_MIN)/NOISE_QUANTIZE_INTERVAL,
--- 42,48 ----
  
  enum {
!   NOISE_MIN = -115,
!   NOISE_MAX = -5,
!   NOISE_MIN_QUANTIZE = -115,
    NOISE_QUANTIZE_INTERVAL = 5,
    NOISE_BIN_SIZE = (NOISE_MAX - NOISE_MIN)/NOISE_QUANTIZE_INTERVAL,
***************
*** 71,74 ****
--- 71,75 ----
    uint32_t noiseTraceLen;
    uint32_t noiseTraceIndex;
+   bool generated;
  } sim_noise_node_t;
  



More information about the Tinyos-2-commits mailing list