Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.9.2, 0.9.3, and 1.0

stable shellext: check return value of std::string::find_last_of

Not knowingly fixing a bug, but not checking it seems dangerous
to me.

substr is specified to throw a std C++ lib out_of_range exception, but we
haven't set up any catch handlers and we are not allowed to throw C++
exceptions across COM interface calls anyway.

Changeset cba2f410d572

Parent b0f4e3208d88

by Adrian Buehlmann

Changes to 2 files · Browse files at cba2f410d572 Showing diff from parent b0f4e3208d88 Diff from another changeset...

 
47
48
49
50
51
52
 
 
 
 
 
 
53
54
55
 
47
48
49
 
 
 
50
51
52
53
54
55
56
57
58
@@ -47,9 +47,12 @@
 CRegStdBase::CRegStdBase (const tstring& key, bool force, HKEY base, REGSAM sam)   : CRegBaseCommon<tstring> (key, force, base, sam)  { - tstring::size_type pos = key.find_last_of(_T('\\')); - m_path = key.substr(0, pos); - m_key = key.substr(pos + 1); + tstring::size_type pos = key.find_last_of(_T('\\')); + if (pos != tstring::npos) + { + m_path = key.substr(0, pos); + m_key = key.substr(pos + 1); + }  }    //////////////////////////////////////////////////////////////////////////////////////////////
 
162
163
164
 
 
165
166
167
 
173
174
175
 
 
176
177
178
 
162
163
164
165
166
167
168
169
 
175
176
177
178
179
180
181
182
@@ -162,6 +162,8 @@
  if (filename.empty())   return filename;   std::string::size_type pos = filename.find_last_of("\\"); + if (pos == std::string::npos) + return "";   std::string myfilename = filename.substr(0, pos);   if (myfilename.size() > 0 && myfilename[myfilename.size()-1] == ':')   myfilename.push_back('\\'); @@ -173,6 +175,8 @@
  if (filename.empty())   return filename;   std::string::size_type pos = filename.find_last_of("\\"); + if (pos == std::string::npos) + return filename;   return filename.substr(pos+1);  }