Jelajahi Sumber

Corrected uninitialized values and invalid memory access

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@49787 15284696-431f-4ddb-bdfa-cd5b030d7da7
Soeren Gebbert 13 tahun lalu
induk
melakukan
08226f2533
1 mengubah file dengan 6 tambahan dan 2 penghapusan
  1. 6 2
      lib/raster3d/cache1.c

+ 6 - 2
lib/raster3d/cache1.c

@@ -90,6 +90,7 @@ void *Rast3d_cache_new(int nofElts, int sizeOfElts, int nofNames,
 		    int (*eltLoadFun) (), void *eltLoadFunData)
 		    int (*eltLoadFun) (), void *eltLoadFunData)
 {
 {
     RASTER3D_cache *tmp;
     RASTER3D_cache *tmp;
+    int i;
 
 
     tmp = Rast3d_malloc(sizeof(RASTER3D_cache));
     tmp = Rast3d_malloc(sizeof(RASTER3D_cache));
     if (tmp == NULL) {
     if (tmp == NULL) {
@@ -114,7 +115,10 @@ void *Rast3d_cache_new(int nofElts, int sizeOfElts, int nofNames,
 	Rast3d_error("Rast3d_cache_new: error in Rast3d_malloc");
 	Rast3d_error("Rast3d_cache_new: error in Rast3d_malloc");
 	return (void *)NULL;
 	return (void *)NULL;
     }
     }
-
+    /* Init the cache lock */
+    for(i = 0; i < tmp->nofElts; i++)
+        tmp->locks[i] = 0;
+        
     tmp->eltRemoveFun = eltRemoveFun;
     tmp->eltRemoveFun = eltRemoveFun;
     tmp->eltRemoveFunData = eltRemoveFunData;
     tmp->eltRemoveFunData = eltRemoveFunData;
     tmp->eltLoadFun = eltLoadFun;
     tmp->eltLoadFun = eltLoadFun;
@@ -196,7 +200,7 @@ static void cache_queue_enqueue(RASTER3D_cache * c, int left, int index)
 	return;
 	return;
     }
     }
 
 
-    if (IS_NOT_IN_QUEUE_ELT(left))
+    if (left >= 0 && IS_NOT_IN_QUEUE_ELT(left))
 	Rast3d_fatal_error("cache_queue_enqueue: position not in queue");
 	Rast3d_fatal_error("cache_queue_enqueue: position not in queue");