summaryrefslogtreecommitdiffstats
path: root/Source/kwsys/SystemInformation.cxx
diff options
context:
space:
mode:
authorBill Hoffman <bill.hoffman@kitware.com>2008-06-01 15:23:22 (GMT)
committerBill Hoffman <bill.hoffman@kitware.com>2008-06-01 15:23:22 (GMT)
commitfc5bc3380e122a82bf3866a59834553e9b4c4825 (patch)
treeafc4ee9efe576c0a1e42c868e69e29674c60ec83 /Source/kwsys/SystemInformation.cxx
parent9f3e67eabf13aa7ec593d90b4eaa4f329127fd7f (diff)
downloadCMake-fc5bc3380e122a82bf3866a59834553e9b4c4825.zip
CMake-fc5bc3380e122a82bf3866a59834553e9b4c4825.tar.gz
CMake-fc5bc3380e122a82bf3866a59834553e9b4c4825.tar.bz2
ENH: avoid divide by zero, temporary fix until cygwin cpu file is read better, bad cpu info is better than a crash
Diffstat (limited to 'Source/kwsys/SystemInformation.cxx')
-rw-r--r--Source/kwsys/SystemInformation.cxx12
1 files changed, 5 insertions, 7 deletions
diff --git a/Source/kwsys/SystemInformation.cxx b/Source/kwsys/SystemInformation.cxx
index 1592237..ed61343 100644
--- a/Source/kwsys/SystemInformation.cxx
+++ b/Source/kwsys/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;
}