MCPcopy Create free account
hub / github.com/Tripwire/tripwire-open-source / InterpretInt

Method InterpretInt

src/core/twlimits.cpp:47–98  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45//=========================================================================
46
47bool cInterpretInt::InterpretInt(const TSTRING& str, int* pi)
48{
49 ASSERT(pi != 0);
50
51 bool fFormatOK = true;
52
53 //
54 // make sure string is not longer than a string representation of LIMIT_MAX
55 //
56 TOSTRINGSTREAM sstr;
57 sstr << cInterpretInt::LIMIT_MAX;
58 if (str.length() > sstr.str().length())
59 fFormatOK = false;
60
61 //
62 // make sure string is not too short
63 //
64 if (fFormatOK && str.length() <= 0)
65 fFormatOK = false;
66
67 //
68 // make sure first character is a digit or the minus sign
69 //
70 if (fFormatOK)
71 {
72 if (!(_T('-') == str[0] || std::isdigit<TCHAR>(str[0], std::locale())))
73 fFormatOK = false;
74 }
75
76 //
77 // make sure all other characters are digits
78 // NOTE:BAM -- this assumes that all digits in all locales are SB characters.
79 // TODO:BAM -- check this...
80 for (TSTRING::size_type j = 1; fFormatOK && j < str.length(); j++)
81 {
82 if (!std::isdigit<TCHAR>(str[j], std::locale()))
83 fFormatOK = false;
84 }
85
86 //
87 // do _ttoi conversion and check that it is within allowable limits
88 //
89 if (fFormatOK)
90 {
91 *pi = _ttoi(str.c_str());
92
93 if (*pi < GetMin() || *pi > GetMax())
94 fFormatOK = false;
95 }
96
97 return fFormatOK;
98}

Callers 4

ValidateMethod · 0.80
CreateFCOSpecsMethod · 0.80
util_GetRecurseDepthFunction · 0.80
InitMethod · 0.80

Calls 2

c_strMethod · 0.80
lengthMethod · 0.45

Tested by

no test coverage detected