From f940356f49bb4aec878d0061a6884792c6936887 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=80=20?= =?UTF-8?q?=D0=97=D0=B0=D1=86=D0=B5=D0=BF=D0=B8=D0=BD?= Date: Fri, 5 May 2017 14:41:54 +0300 Subject: [PATCH] [core] Added additional warnings about unused results to string_util to_* method to avoid unexcpected behaviour during converting the strings to int --- base/string_utils.hpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/base/string_utils.hpp b/base/string_utils.hpp index 8fc2228b40..1ebec6dc13 100644 --- a/base/string_utils.hpp +++ b/base/string_utils.hpp @@ -1,6 +1,7 @@ #pragma once #include "base/buffer_vector.hpp" +#include "base/macros.hpp" #include "base/stl_add.hpp" #include @@ -337,28 +338,29 @@ bool IsInArray(T(&arr)[N], TT const & t) /// @name From string to numeric. //@{ -bool to_int(char const * s, int & i, int base = 10); -bool to_uint(char const * s, unsigned int & i, int base = 10); -bool to_uint64(char const * s, uint64_t & i); -bool to_int64(char const * s, int64_t & i); -bool to_float(char const * s, float & f); -bool to_double(char const * s, double & d); +WARN_UNUSED_RESULT bool to_int(char const * s, int & i, int base = 10); +WARN_UNUSED_RESULT bool to_uint(char const * s, unsigned int & i, int base = 10); +WARN_UNUSED_RESULT bool to_uint64(char const * s, uint64_t & i); +WARN_UNUSED_RESULT bool to_int64(char const * s, int64_t & i); +WARN_UNUSED_RESULT bool to_float(char const * s, float & f); +WARN_UNUSED_RESULT bool to_double(char const * s, double & d); -inline bool is_number(std::string const & s) +WARN_UNUSED_RESULT inline bool is_number(std::string const & s) { int64_t dummy; return to_int64(s.c_str(), dummy); } -inline bool to_int(std::string const & s, int & i, int base = 10) { return to_int(s.c_str(), i, base); } -inline bool to_uint(std::string const & s, unsigned int & i, int base = 10) +WARN_UNUSED_RESULT inline bool to_int(std::string const & s, int & i, int base = 10) { return to_int(s.c_str(), i, base); } +WARN_UNUSED_RESULT inline bool to_uint(std::string const & s, unsigned int & i, int base = 10) { return to_uint(s.c_str(), i, base); } -inline bool to_uint64(std::string const & s, uint64_t & i) { return to_uint64(s.c_str(), i); } -inline bool to_int64(std::string const & s, int64_t & i) { return to_int64(s.c_str(), i); } -inline bool to_float(std::string const & s, float & f) { return to_float(s.c_str(), f); } -inline bool to_double(std::string const & s, double & d) { return to_double(s.c_str(), d); } + +WARN_UNUSED_RESULT inline bool to_uint64(std::string const & s, uint64_t & i) { return to_uint64(s.c_str(), i); } +WARN_UNUSED_RESULT inline bool to_int64(std::string const & s, int64_t & i) { return to_int64(s.c_str(), i); } +WARN_UNUSED_RESULT inline bool to_float(std::string const & s, float & f) { return to_float(s.c_str(), f); } +WARN_UNUSED_RESULT inline bool to_double(std::string const & s, double & d) { return to_double(s.c_str(), d); } //@} /// @name From numeric to string.