|
10 | 10 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
11 | 11 | */ |
12 | 12 |
|
| 13 | +#include <cstdio> |
13 | 14 | #include <cstring> |
14 | 15 | #include <functional> |
15 | 16 | #include <iostream> |
|
23 | 24 | #pragma GCC diagnostic ignored "-Wattributes" |
24 | 25 | #endif |
25 | 26 |
|
26 | | -#ifdef _MSC_VER |
27 | | -#pragma warning(disable : 4996) // do not complain about sprintf |
28 | | -#endif |
29 | | - |
30 | 27 | #include <map> |
31 | 28 | #include "behaviortree_cpp/xml_parsing.h" |
32 | 29 | #include "tinyxml2/tinyxml2.h" |
@@ -239,8 +236,8 @@ void XMLParser::PImpl::loadDocImpl(XMLDocument* doc, bool add_includes) |
239 | 236 | { |
240 | 237 | if (doc->Error()) |
241 | 238 | { |
242 | | - char buffer[200]; |
243 | | - sprintf(buffer, "Error parsing the XML: %s", doc->ErrorStr()); |
| 239 | + char buffer[512]; |
| 240 | + snprintf(buffer, sizeof buffer, "Error parsing the XML: %s", doc->ErrorStr()); |
244 | 241 | throw RuntimeError(buffer); |
245 | 242 | } |
246 | 243 |
|
@@ -350,14 +347,14 @@ void VerifyXML(const std::string& xml_text, |
350 | 347 | if (xml_error) |
351 | 348 | { |
352 | 349 | char buffer[512]; |
353 | | - sprintf(buffer, "Error parsing the XML: %s", doc.ErrorName()); |
| 350 | + snprintf(buffer, sizeof buffer, "Error parsing the XML: %s", doc.ErrorName()); |
354 | 351 | throw RuntimeError(buffer); |
355 | 352 | } |
356 | 353 |
|
357 | 354 | //-------- Helper functions (lambdas) ----------------- |
358 | 355 | auto ThrowError = [&](int line_num, const std::string& text) { |
359 | 356 | char buffer[512]; |
360 | | - sprintf(buffer, "Error at line %d: -> %s", line_num, text.c_str()); |
| 357 | + snprintf(buffer, sizeof buffer, "Error at line %d: -> %s", line_num, text.c_str()); |
361 | 358 | throw RuntimeError(buffer); |
362 | 359 | }; |
363 | 360 |
|
|
0 commit comments