# System.AccessViolationException occured in Sprintf_s

This topic is 3873 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

##### Share on other sites
Quote:
 The array's I defined are extremely large as well the cookie is only 640 characters long not including null terminating character but when I checked the value of the resulting retrival of the cookie it was trunceted so thats why I had to increase the size to that exact value for the function to succeed.

All of this is representative of a very poor methodology for string data handling that was necessary for C. You are obviously not using C, so the solution is to use proper idioms for string formatting. The access violation is almost certainly related to this manual buffer management, size-hacking, and/or mistyping a format specifier in some fashion.

You can replace your use of sprintf_s with std::stringstream:
std::stringstream str;  str << "GET /?gtype=" << gtype << ...;  //...  iResult = send( ConnectSocket, str.str().c_str(), str.str().size(), 0 );

This is both typesafe and far less prone to error.