1 // Copyright 2017 Google Inc. All Rights Reserved.
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 
4 // Implementation of "my_api".
5 #include "my_api.h"
6 
7 #include <vector>
8 
9 // Do some computations with 'str', return the result.
10 // This function contains a bug. Can you spot it?
DoStuff(const std::string & str)11 size_t DoStuff(const std::string &str) {
12   std::vector<int> Vec({0, 1, 2, 3, 4});
13   size_t Idx = 0;
14   if (str.size() > 5)
15     Idx++;
16   if (str.find("foo") != std::string::npos)
17     Idx++;
18   if (str.find("bar") != std::string::npos)
19     Idx++;
20   if (str.find("ouch") != std::string::npos)
21     Idx++;
22   if (str.find("omg") != std::string::npos)
23     Idx++;
24   return Vec[Idx];
25 }
26