1 // Copyright 2020 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Implementation of "my_api". 16 #include "my_api.h" 17 18 #include <vector> 19 20 // Do some computations with 'str', return the result. 21 // This function contains a bug. Can you spot it? DoStuff(const std::string & str)22size_t DoStuff(const std::string &str) { 23 std::vector<int> Vec({0, 1, 2, 3, 4}); 24 size_t Idx = 0; 25 if (str.size() > 5) 26 Idx++; 27 if (str.find("foo") != std::string::npos) 28 Idx++; 29 if (str.find("bar") != std::string::npos) 30 Idx++; 31 if (str.find("ouch") != std::string::npos) 32 Idx++; 33 if (str.find("omg") != std::string::npos) 34 Idx++; 35 return Vec[Idx]; 36 } 37