From 8e116ee96b8637c06b13657a78db28cd5a242df0 Mon Sep 17 00:00:00 2001
From: Bill Hoffman <bill.hoffman@kitware.com>
Date: Sun, 1 Jun 2008 11:23:22 -0400
Subject: [PATCH] ENH: avoid divide by zero, temporary fix until cygwin cpu
 file is read better, bad cpu info is better than a crash

---
 SystemInformation.cxx | 12 +++++-------
 kwsysDateStamp.cmake  |  4 ++--
 2 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/SystemInformation.cxx b/SystemInformation.cxx
index 08be90f..ff21365 100644
--- a/SystemInformation.cxx
+++ b/SystemInformation.cxx
@@ -2158,9 +2158,7 @@ int SystemInformationImplementation::RetreiveInformationFromCpuInfoFile()
     fileSize++;
     }
   fclose( fd );
-  
   buffer.resize(fileSize-2);
-
   // Number of logical CPUs (combination of multiple processors, multi-core
   // and hyperthreading)
   size_t pos = buffer.find("processor\t");
@@ -2184,16 +2182,18 @@ int SystemInformationImplementation::RetreiveInformationFromCpuInfoFile()
     idc = this->ExtractValueFromCpuInfoFile(buffer,"physical id",
                                             this->CurrentPositionInFile+1);
     }
-
   // Physical ids returned by Linux don't distinguish cores.
   // We want to record the total number of cores in this->NumberOfPhysicalCPU
   // (checking only the first proc)
   kwsys_stl::string cores =
                         this->ExtractValueFromCpuInfoFile(buffer,"cpu cores");
   int numberOfCoresPerCPU=atoi(cores.c_str());
-
   this->NumberOfPhysicalCPU=numberOfCoresPerCPU*(maxId+1);
-
+  // have to have one, and need to avoid divied by zero
+  if(this->NumberOfPhysicalCPU <= 0)
+    {
+    this->NumberOfPhysicalCPU = 1;
+    }
   // LogicalProcessorsPerPhysical>1 => hyperthreading.
   this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical=
                             this->NumberOfLogicalCPU/this->NumberOfPhysicalCPU;
@@ -2221,8 +2221,6 @@ int SystemInformationImplementation::RetreiveInformationFromCpuInfoFile()
     cacheSize = cacheSize.substr(0,pos);
     }
   this->Features.L1CacheSize = atoi(cacheSize.c_str());
-
-
   return 1;
 }
 
diff --git a/kwsysDateStamp.cmake b/kwsysDateStamp.cmake
index fad7d0b..8efb4e2 100644
--- a/kwsysDateStamp.cmake
+++ b/kwsysDateStamp.cmake
@@ -4,7 +4,7 @@
 SET(KWSYS_DATE_STAMP_YEAR  2008)
 
 # KWSys version date month component.  Format is MM.
-SET(KWSYS_DATE_STAMP_MONTH 05)
+SET(KWSYS_DATE_STAMP_MONTH 06)
 
 # KWSys version date day component.  Format is DD.
-SET(KWSYS_DATE_STAMP_DAY   31)
+SET(KWSYS_DATE_STAMP_DAY   01)
-- 
GitLab