fix: Stop using ato* for string to num conversion
atoi, atof and so on have undefined behavior if anything goes wrong. We now use strto*, but without error checking. In most places overflows and the like *should* not happen. String to number conversions are only used when reading data from other applications or from the config, if another application gives unparsable strings or too large numbers, then most likely there is something wrong with that application. If the error comes from the user config, then the user has to live with values provided by strto* on error (which are very reasonable) Fixes #1201
This commit is contained in:
parent
cc334e5040
commit
095d68fad0
10 changed files with 22 additions and 22 deletions
src/components
|
@ -248,23 +248,23 @@ bar::bar(connection& conn, signal_emitter& emitter, const config& config, const
|
|||
auto offsetx = m_conf.get(m_conf.section(), "offset-x", ""s);
|
||||
auto offsety = m_conf.get(m_conf.section(), "offset-y", ""s);
|
||||
|
||||
m_opts.size.w = atoi(w.c_str());
|
||||
m_opts.size.h = atoi(h.c_str());
|
||||
m_opts.offset.x = atoi(offsetx.c_str());
|
||||
m_opts.offset.y = atoi(offsety.c_str());
|
||||
m_opts.size.w = std::strtol(w.c_str(), nullptr, 10);
|
||||
m_opts.size.h = std::strtol(h.c_str(), nullptr, 10);
|
||||
m_opts.offset.x = std::strtol(offsetx.c_str(), nullptr, 10);
|
||||
m_opts.offset.y = std::strtol(offsety.c_str(), nullptr, 10);
|
||||
|
||||
// Evaluate percentages
|
||||
double tmp;
|
||||
if ((tmp = atof(w.c_str())) && w.find('%') != string::npos) {
|
||||
if ((tmp = strtof(w.c_str(), nullptr)) && w.find('%') != string::npos) {
|
||||
m_opts.size.w = math_util::percentage_to_value<double>(tmp, m_opts.monitor->w);
|
||||
}
|
||||
if ((tmp = atof(h.c_str())) && h.find('%') != string::npos) {
|
||||
if ((tmp = strtof(h.c_str(), nullptr)) && h.find('%') != string::npos) {
|
||||
m_opts.size.h = math_util::percentage_to_value<double>(tmp, m_opts.monitor->h);
|
||||
}
|
||||
if ((tmp = atof(offsetx.c_str())) != 0 && offsetx.find('%') != string::npos) {
|
||||
if ((tmp = strtof(offsetx.c_str(), nullptr)) != 0 && offsetx.find('%') != string::npos) {
|
||||
m_opts.offset.x = math_util::percentage_to_value<double>(tmp, m_opts.monitor->w);
|
||||
}
|
||||
if ((tmp = atof(offsety.c_str())) != 0 && offsety.find('%') != string::npos) {
|
||||
if ((tmp = strtof(offsety.c_str(), nullptr)) != 0 && offsety.find('%') != string::npos) {
|
||||
m_opts.offset.y = math_util::percentage_to_value<double>(tmp, m_opts.monitor->h);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue