mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-28 03:11:47 +00:00
fix: handle malformed printer progress values safely
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
#include "ReleaseNote.hpp"
|
#include "ReleaseNote.hpp"
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <charconv>
|
||||||
#include <codecvt>
|
#include <codecvt>
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
#include <boost/typeof/typeof.hpp>
|
#include <boost/typeof/typeof.hpp>
|
||||||
@@ -2602,9 +2603,14 @@ void MachineObject::set_print_state(std::string status)
|
|||||||
// why: printer agents can report progress without BBL cloud task identity.
|
// why: printer agents can report progress without BBL cloud task identity.
|
||||||
void MachineObject::update_print_progress(const json& value)
|
void MachineObject::update_print_progress(const json& value)
|
||||||
{
|
{
|
||||||
if (value.is_string())
|
if (value.is_string()) {
|
||||||
mc_print_percent = stoi(value.get<std::string>());
|
const std::string progress = value.get<std::string>();
|
||||||
else if (value.is_number_integer())
|
int parsed_progress;
|
||||||
|
const auto result = std::from_chars(progress.data(), progress.data() + progress.size(), parsed_progress);
|
||||||
|
if (result.ec != std::errc{} || result.ptr != progress.data() + progress.size())
|
||||||
|
return;
|
||||||
|
mc_print_percent = parsed_progress;
|
||||||
|
} else if (value.is_number_integer())
|
||||||
mc_print_percent = value.get<int>();
|
mc_print_percent = value.get<int>();
|
||||||
else
|
else
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user