Skip to content
Merged
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
12 changes: 12 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,24 @@ int main(int argc, char** argv, char** envp) {
}
case 's': {
float value;
#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 200000
try {
size_t pos;
value = std::stof(optarg, &pos);
if (pos != strlen(optarg))
throw std::invalid_argument("");
} catch (...) {
std::cerr << "Invalid scale value: " << optarg << "\n";
exit(1);
}
#else
auto result = std::from_chars(optarg, optarg + strlen(optarg), value);

if (result.ec != std::errc() || result.ptr != optarg + strlen(optarg)) {
std::cerr << "Invalid scale value: " << optarg << "\n";
exit(1);
}
#endif

if (value < 1.0f || value > 10.0f) {
std::cerr << "Scale must be between 1 and 10!\n";
Expand Down
Loading