title: /gs option causing program to throw exception
body: <p>Recently, I've been trying to make a little test program to communicate with a MySQL server in C++. I'm currently using MySQL Connector/C++ as my API to connect to my database server. It took me a very long time to get it running, because oracle/mysql has little to no documentation of how to use connector/c++ with Visual Studio 10+.</p>
  
  <p>Finally after getting everything working, there seems to be some issue when the application tries to exit. It throws the following unhandled exception: </p>
  
  <p><code>Unhandled exception at 0x00C62291 in mysql2.exe: Stack cookie instrumentation code detected a stack-based buffer overrun.</code></p>
  
  <p>After researching about the error, I figured out it was due to the "security check" option (/gs compiler option). When I disable this compiler option, the application exits gracefully. </p>
  
  <p>I have a feeling that I should not turn it off, as it is the default option in Visual Studio 2012 (and possibly other versions?)</p>
  
  <p>My questions are:</p>
  
  <ul>
  <li>Why is this /gs compiler option causing the unhandled exception?</li>
  <li>Is it safe or okay to turn off the /gs compiler option?</li>
  </ul>
  
  <p>Here is the piece of code the unhandled exception points to (inside a file, called: gs_report.c):</p>
  
  <pre><code>#if defined (_M_IX86) || defined (_M_X64)
      if (IsProcessorFeaturePresent(PF_FASTFAIL_AVAILABLE))
  #endif  /* defined (_M_IX86) || defined (_M_X64) */
      __fastfail(FAST_FAIL_STACK_COOKIE_CHECK_FAILURE);
  </code></pre>
  
  <p>Here is my application code:</p>
  
  <pre><code>/* Standard C++ includes */
  #include &lt;stdlib.h&gt;
  #include &lt;iostream&gt;
  
  /*
  Include directly the different
  headers from cppconn/ and mysql_driver.h + mysql_util.h
  (and mysql_connection.h). This will reduce your build time!
  */
  #include "mysql_connection.h"
  #include "mysql_driver.h"
  
  #include &lt;cppconn/driver.h&gt;
  #include &lt;cppconn/exception.h&gt;
  #include &lt;cppconn/resultset.h&gt;
  #include &lt;cppconn/statement.h&gt;
  #include &lt;cppconn/prepared_statement.h&gt;
  
  using namespace std;
  
  int main(void)
  {
      cout &lt;&lt; endl;
      cout &lt;&lt; "Let's have MySQL count from 10 to 1..." &lt;&lt; endl;
  
      try {
          sql::Driver *driver;
          sql::Connection *con;
          sql::Statement *stmt;
          sql::ResultSet *res;
          sql::PreparedStatement *pstmt;
  
          /* Create a connection */
          driver = sql::mysql::get_driver_instance();
          con = driver-&gt;connect("tcp://127.0.0.1:3306", "root", "MSxa5y");
          /* Connect to the MySQL test database */
          con-&gt;setSchema("test");
  
          stmt = con-&gt;createStatement();
          stmt-&gt;execute("DROP TABLE IF EXISTS test");
          stmt-&gt;execute("CREATE TABLE test(id INT)");
          delete stmt;
  
          /* '?' is the supported placeholder syntax */
          pstmt = con-&gt;prepareStatement("INSERT INTO test(id) VALUES (?)");
          for (int i = 1; i &lt;= 10; i++) {
              pstmt-&gt;setInt(1, i);
              pstmt-&gt;executeUpdate();
          }
          delete pstmt;
  
          /* Select in ascending order */
          pstmt = con-&gt;prepareStatement("SELECT id FROM test ORDER BY id ASC");
          res = pstmt-&gt;executeQuery();
  
          /* Fetch in reverse = descending order! */
          res-&gt;afterLast();
          while (res-&gt;previous())
              cout &lt;&lt; "\t... MySQL counts: " &lt;&lt; res-&gt;getInt("id") &lt;&lt; endl;
          delete res;
  
          delete pstmt;
          delete con;
  
      } catch (sql::SQLException &amp;e) {
          cout &lt;&lt; "# ERR: SQLException in " &lt;&lt; __FILE__;
          cout &lt;&lt; "() on line " &lt;&lt; __LINE__ &lt;&lt; endl;
          cout &lt;&lt; "# ERR: " &lt;&lt; e.what();
          cout &lt;&lt; " (MySQL error code: " &lt;&lt; e.getErrorCode();
          cout &lt;&lt; ", SQLState: " &lt;&lt; e.getSQLState() &lt;&lt; " )" &lt;&lt; endl;
      }
  
      cout &lt;&lt; endl;
  
      return EXIT_SUCCESS;
  }
  </code></pre>