From 70df2276890d08240391adee07408f9495c78db5 Mon Sep 17 00:00:00 2001 From: El Potaeto Date: Sun, 11 Jan 2015 01:04:54 +0100 Subject: [PATCH] dump function is now memory safe --- R-package/src/xgboost_R.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R-package/src/xgboost_R.cpp b/R-package/src/xgboost_R.cpp index 9320547df..5a8ddbf52 100644 --- a/R-package/src/xgboost_R.cpp +++ b/R-package/src/xgboost_R.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "xgboost_R.h" #include "wrapper/xgboost_wrapper.h" #include "src/utils/utils.h" @@ -280,11 +281,10 @@ extern "C" { asInteger(with_stats), &olen); SEXP out = PROTECT(allocVector(STRSXP, olen)); - char buffer [2000]; for (size_t i = 0; i < olen; ++i) { - memset(buffer, 0, sizeof buffer); - sprintf (buffer, "booster[%u]:\n%s", static_cast(i), res[i]); - SET_STRING_ELT(out, i, mkChar(buffer)); + stringstream stream; + stream << "booster["<