[GRASS-SVN] r67839 - grass-addons/grass7/raster/r.futures/r.futures.pga

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Feb 15 18:56:25 PST 2016


Author: wenzeslaus
Date: 2016-02-15 18:56:25 -0800 (Mon, 15 Feb 2016)
New Revision: 67839

Modified:
   grass-addons/grass7/raster/r.futures/r.futures.pga/main.c
Log:
r.futures: update size when enlarging list

Fixes segfaut.

Remove special condition for no subregions
which was part of the old code.
It is not needed and harmful now.


Modified: grass-addons/grass7/raster/r.futures/r.futures.pga/main.c
===================================================================
--- grass-addons/grass7/raster/r.futures/r.futures.pga/main.c	2016-02-16 01:29:20 UTC (rev 67838)
+++ grass-addons/grass7/raster/r.futures/r.futures.pga/main.c	2016-02-16 02:56:25 UTC (rev 67839)
@@ -1283,7 +1283,9 @@
     if (nToConvert > 0) {
         /* if not enough cells to convert then alter number required */
         if (nToConvert > pLandscape->num_undevSites[regionID]) {
-            G_warning("Not enough undeveloped sites... converting all");
+            G_warning("Not enough undeveloped sites (requested: %d,"
+                      " available: %d). Converting all available.",
+                       nToConvert, pLandscape->num_undevSites[regionID]);
             nToConvert = pLandscape->num_undevSites[regionID];
         }
         /* update in stochastic fashion */
@@ -1773,8 +1775,7 @@
                 sParams.overflowDevDemands[i] = 0;
             }
             readDevDemand(&sParams);
-            if (sParams.num_Regions > 1)
-                readDevPotParams(&sParams, opt.devpotParamsFile->answer);
+            readDevPotParams(&sParams, opt.devpotParamsFile->answer);
             if (readParcelSizes(&sLandscape, &sParams)) {
                 //testDevPressure(&sLandscape, &sParams);
                 /* do calculation and dump result */
@@ -1874,7 +1875,11 @@
                                       pThis->index_region);
 
                     if (pLandscape->num_undevSites[id] >= pLandscape->asUndevs_ns[id]) {
-                        pLandscape->asUndevs[id] = (t_Undev *) G_realloc(pLandscape->asUndevs[id], pLandscape->asUndevs_ns[id] * 2 * sizeof(t_Undev));
+                        size_t new_size = 2 * pLandscape->asUndevs_ns[id];
+                        pLandscape->asUndevs[id] =
+                            (t_Undev *) G_realloc(pLandscape->asUndevs[id],
+                                                  new_size * sizeof(t_Undev));
+                        pLandscape->asUndevs_ns[id] = new_size;
                     }
                     pLandscape->asUndevs[id][pLandscape->num_undevSites[id]].
                         cellID = i;



More information about the grass-commit mailing list