1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-25 02:50:08 +03:00

bug #1402: Always parse int values as floats and then truncate them

This commit is contained in:
Ruben S. Montero 2012-08-07 02:12:21 +02:00
parent 38205fd6d1
commit 7dd75027e3
2 changed files with 11 additions and 32 deletions

View File

@ -173,7 +173,6 @@ int Host::update_info(string &parse_str)
{
char * error_msg;
int rc;
float fv;
rc = obj_template->parse(parse_str, &error_msg);
@ -185,20 +184,14 @@ int Host::update_info(string &parse_str)
return -1;
}
get_template_attribute("TOTALCPU", fv);
host_share.max_cpu = static_cast<int>(fv);
get_template_attribute("TOTALMEMORY", fv);
host_share.max_mem = static_cast<int>(fv);
get_template_attribute("TOTALCPU",host_share.max_cpu);
get_template_attribute("TOTALMEMORY",host_share.max_mem);
get_template_attribute("FREECPU", fv);
host_share.free_cpu = static_cast<int>(fv);
get_template_attribute("FREEMEMORY", fv);
host_share.free_mem = static_cast<int>(fv);
get_template_attribute("FREECPU",host_share.free_cpu);
get_template_attribute("FREEMEMORY",host_share.free_mem);
get_template_attribute("USEDCPU", fv);
host_share.used_cpu = static_cast<int>(fv);
get_template_attribute("USEDMEMORY", fv);
host_share.used_mem = static_cast<int>(fv);
get_template_attribute("USEDCPU",host_share.used_cpu);
get_template_attribute("USEDMEMORY",host_share.used_mem);
return 0;
}

View File

@ -417,27 +417,13 @@ bool Template::get(
const string& name,
int& value) const
{
string sval;
float fvalue;
bool rc;
get(name, sval);
rc = get(name, fvalue);
value = static_cast<int>(fvalue);
if ( sval == "" )
{
value = 0;
return false;
}
istringstream iss(sval);
iss >> value;
if (iss.fail() || !iss.eof())
{
value = 0;
return false;
}
return true;
return rc;
}
/* -------------------------------------------------------------------------- */