mirror of
https://github.com/polybar/polybar.git
synced 2026-03-02 14:24:01 +00:00
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:
@ -76,7 +76,7 @@ namespace modules {
|
||||
auto spacing = m_formatter->get(get_format())->spacing;
|
||||
for (auto&& item : m_levels[m_level]->items) {
|
||||
/*
|
||||
* Depending on whether the menu items are to the left or right of the toggle label, the items need to be
|
||||
* Depending on whether the menu items are to the left or right of the toggle label, the items need to be
|
||||
* drawn before or after the spacings and the separator
|
||||
*
|
||||
* If the menu expands to the left, the separator should be drawn on the right side because otherwise the menu
|
||||
@ -132,7 +132,7 @@ namespace modules {
|
||||
if (level.empty()) {
|
||||
level = "0";
|
||||
}
|
||||
m_level = std::atoi(level.c_str());
|
||||
m_level = std::strtol(level.c_str(), nullptr, 10);
|
||||
m_log.info("%s: Opening menu level '%i'", name(), static_cast<int>(m_level));
|
||||
|
||||
if (static_cast<size_t>(m_level) >= m_levels.size()) {
|
||||
|
||||
Reference in New Issue
Block a user