Use snprintf

release/4.3a0
Frank Dellaert 2023-01-28 12:00:40 -08:00
parent a611d607b3
commit f3284a9d81
2 changed files with 7 additions and 6 deletions

View File

@ -71,9 +71,9 @@ void LabeledSymbol::print(const std::string& s) const {
/* ************************************************************************* */ /* ************************************************************************* */
LabeledSymbol::operator std::string() const { LabeledSymbol::operator std::string() const {
char buf[100]; char buffer[100];
sprintf(buf, "%c%c%zu", c_, label_, j_); snprintf(buffer, 100, "%c%c%llu", c_, label_, j_);
return std::string(buf); return std::string(buffer);
} }
/* ************************************************************************* */ /* ************************************************************************* */

View File

@ -22,6 +22,7 @@
#include <list> #include <list>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <cstdio>
namespace gtsam { namespace gtsam {
@ -55,9 +56,9 @@ bool Symbol::equals(const Symbol& expected, double tol) const {
} }
Symbol::operator std::string() const { Symbol::operator std::string() const {
char buf[10]; char buffer[10];
sprintf(buf, "%c%zu", c_, j_); snprintf(buffer, 10, "%c%llu", c_, j_);
return std::string(buf); return std::string(buffer);
} }
static Symbol make(gtsam::Key key) { return Symbol(key);} static Symbol make(gtsam::Key key) { return Symbol(key);}