Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 49 additions & 44 deletions src/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -916,57 +916,62 @@ int TimeValue::read(const std::string& buf) {
spos = 4;
}

auto hi = std::stoi(buf.substr(0, 2));
if (hi < 0 || hi > 23)
return printWarning();
time_.hour = hi;
if (buf.size() > 3) {
auto mi = std::stoi(buf.substr(mpos, 2));
if (mi < 0 || mi > 59)
try {
auto hi = std::stoi(buf.substr(0, 2));
if (hi < 0 || hi > 23)
return printWarning();
time_.minute = std::stoi(buf.substr(mpos, 2));
} else {
time_.minute = 0;
}
if (buf.size() > 5) {
auto si = std::stoi(buf.substr(spos, 2));
if (si < 0 || si > 60)
return printWarning();
time_.second = std::stoi(buf.substr(spos, 2));
} else {
time_.second = 0;
}

auto fpos = buf.find('+');
if (fpos == std::string::npos)
fpos = buf.find('-');

if (fpos != std::string::npos) {
auto format = buf.substr(fpos, buf.size());
auto posColon = format.find(':');
if (posColon == std::string::npos) {
// Extended format
auto tzhi = std::stoi(format.substr(0, 3));
if (tzhi < -23 || tzhi > 23)
time_.hour = hi;
if (buf.size() > 3) {
auto mi = std::stoi(buf.substr(mpos, 2));
if (mi < 0 || mi > 59)
return printWarning();
time_.minute = std::stoi(buf.substr(mpos, 2));
Comment on lines +925 to +928
} else {
time_.minute = 0;
}
if (buf.size() > 5) {
auto si = std::stoi(buf.substr(spos, 2));
if (si < 0 || si > 60)
return printWarning();
time_.tzHour = tzhi;
if (format.size() > 3) {
int minute = std::stoi(format.substr(3));
time_.second = std::stoi(buf.substr(spos, 2));
} else {
time_.second = 0;
}

auto fpos = buf.find('+');
if (fpos == std::string::npos)
fpos = buf.find('-');

if (fpos != std::string::npos) {
auto format = buf.substr(fpos, buf.size());
auto posColon = format.find(':');
if (posColon == std::string::npos) {
// Extended format
auto tzhi = std::stoi(format.substr(0, 3));
if (tzhi < -23 || tzhi > 23)
return printWarning();
time_.tzHour = tzhi;
if (format.size() > 3) {
int minute = std::stoi(format.substr(3));
if (minute < 0 || minute > 59)
return printWarning();
time_.tzMinute = time_.tzHour < 0 ? -minute : minute;
}
} else {
// Basic format
auto tzhi = std::stoi(format.substr(0, posColon));
if (tzhi < -23 || tzhi > 23)
return printWarning();
time_.tzHour = tzhi;
int minute = std::stoi(format.substr(posColon + 1));
if (minute < 0 || minute > 59)
return printWarning();
time_.tzMinute = time_.tzHour < 0 ? -minute : minute;
}
} else {
// Basic format
auto tzhi = std::stoi(format.substr(0, posColon));
if (tzhi < -23 || tzhi > 23)
return printWarning();
time_.tzHour = tzhi;
int minute = std::stoi(format.substr(posColon + 1));
if (minute < 0 || minute > 59)
return printWarning();
time_.tzMinute = time_.tzHour < 0 ? -minute : minute;
}
} catch (std::exception&) {
// std::stoi might throw an exception if the syntax is invalid.
return printWarning();
}
return 0;
}
Expand Down
Loading