X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/d8b71540598af16b7d9891dc015d5972908c7754..b27841d687ec9e84983340b5581376dfb24010ea:/projects/stargazer/plugins/other/smux/types.cpp diff --git a/projects/stargazer/plugins/other/smux/types.cpp b/projects/stargazer/plugins/other/smux/types.cpp index f9c5eb50..8132bca0 100644 --- a/projects/stargazer/plugins/other/smux/types.cpp +++ b/projects/stargazer/plugins/other/smux/types.cpp @@ -1,9 +1,16 @@ +#include "types.h" + #include #include #include #include -#include "types.h" +namespace +{ + +bool ParseArcs(const char * str, ptrdiff_t length, unsigned * a, size_t * pos); +bool StringToArcs(const char * str, size_t length, std::vector & arcs); +bool AppendToArcs(const char * str, size_t length, std::vector & arcs); bool ParseArcs(const char * str, ptrdiff_t length, unsigned * a, size_t * pos) { @@ -15,14 +22,14 @@ if (*left == '.') size_t arcPos = 0; while ((left - str) < length) { - char * pos = NULL; - unsigned arc = strtoul(left, &pos, 10); - if (pos == left) + char * p = NULL; + unsigned arc = static_cast(strtoul(left, &p, 10)); + if (p == left) return false; a[arcPos++] = arc; if (arcPos >= 1024) return false; - left = pos + 1; + left = p + 1; } *pos = arcPos; return true; @@ -52,13 +59,17 @@ std::copy(&a[0], &a[pos], std::back_inserter(arcs)); return true; } +} + OID::OID(const std::string & str) + : arcs() { if (!StringToArcs(str.c_str(), str.length(), arcs)) throw std::runtime_error("Invalid oid"); } OID::OID(const char * str, size_t length) + : arcs() { if (!StringToArcs(str, length, arcs)) throw std::runtime_error("Invalid oid"); @@ -70,12 +81,14 @@ OID::OID(const std::vector & a) } OID::OID(const unsigned * a, size_t length) + : arcs() { std::vector newArcs(a, a + length); arcs.swap(newArcs); } OID::OID(OBJECT_IDENTIFIER_t * oid) + : arcs() { unsigned a[1024]; int count = OBJECT_IDENTIFIER_get_arcs(oid, a, sizeof(a[0]), 1024); @@ -178,7 +191,7 @@ return stream.str(); void OID::ToOID(OBJECT_IDENTIFIER_t * oid) const { -OBJECT_IDENTIFIER_set_arcs(oid, &arcs.front(), sizeof(unsigned), arcs.size()); +OBJECT_IDENTIFIER_set_arcs(oid, &arcs.front(), sizeof(unsigned), static_cast(arcs.size())); } OID & OID::operator=(const OID & rvalue)