Skip to content

Commit

Permalink
trying stringstream for double (stod)
Browse files Browse the repository at this point in the history
  • Loading branch information
M4tteoP committed Aug 17, 2022
1 parent 6651741 commit b02f740
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
6 changes: 0 additions & 6 deletions .vscode/settings.json

This file was deleted.

13 changes: 7 additions & 6 deletions src/actions/rule_id.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include <iostream>
#include <string>
#include <charconv>
#include <sstream>

#include "modsecurity/transaction.h"
#include "modsecurity/rule.h"
Expand All @@ -28,11 +28,12 @@ namespace actions {

bool RuleId::init(std::string *error) {
std::string a = m_parser_payload;

const auto format = std::chars_format::fixed;
const auto conv_res = std::from_chars(a.data(), a.data() + a.size(), m_ruleId, format);
if (conv_res.ec == std::errc::invalid_argument || conv_res.ec == std::errc::result_out_of_range) {
// Conversion error

std::stringstream ss;
ss<<a;
ss>>m_ruleId;
if (ss.fail()) {
ss.clear();
m_ruleId = 0;
error->assign("The input \"" + a + "\" does not " \
"seems to be a valid rule id.");
Expand Down

0 comments on commit b02f740

Please sign in to comment.