Commit 7e0e06b7 authored by Thomas Braun's avatar Thomas Braun
Browse files

src/log4tango/Level.cpp: Prefer parse_as

This is safer than stroul. This also allows us to drop the exception in
.pre-commit.config.yaml.
parent 1fef0a4e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ repos:
    - id: check_unsafe_number_parsing
      name: Check that no unsafe string number conversion routines are used
      types_or: [c++, c]
      exclude: '(src/common/parse\.cpp)|(src/log4tango/Level\.cpp)'
      exclude: '(src/common/parse\.cpp)'
      args: [--multiline]
      entry: "(ato(i|l|ll|f)|strto(l|ll|ul|ull|f|d|ld)|strtoimax|strtoumax|sto(i|l|ll))"
      language: pygrep
+8 −3
Original line number Diff line number Diff line
@@ -8,6 +8,9 @@

#include <tango/common/log4tango/Level.h>

#include <tango/internal/parse.h>

#include <tango/common/idl_wrapper.h>
#include <tango/common/log4tango/Portability.h>

#include <cstdlib>
@@ -76,9 +79,11 @@ Level::Value Level::get_value(const std::string &level_name)
    }
    if(value == -1)
    {
        char *end_pointer;
        value = std::strtoul(level_name.c_str(), &end_pointer, 10);
        if(*end_pointer != 0)
        try
        {
            return Tango::detail::parse_as<Level::Value>(level_name);
        }
        catch(Tango::DevFailed &)
        {
            throw std::invalid_argument(std::string("unknown level name: '") + level_name + "'");
        }