mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-20 20:33:34 +08:00
C++ library usage fix: snprintf() may or may not be in std::
This commit is contained in:
@@ -503,7 +503,8 @@ public:
|
||||
const SizeType max_size = capacity() - size();
|
||||
|
||||
// We have one extra byte for the null terminator, hence +1
|
||||
const int ret = std::snprintf(reinterpret_cast<char*>(ptr), max_size + 1, format, value);
|
||||
using namespace std; // For snprintf()
|
||||
const int ret = snprintf(reinterpret_cast<char*>(ptr), max_size + 1, format, value);
|
||||
|
||||
for (int i = 0; i < std::min(ret, int(max_size)); i++)
|
||||
{
|
||||
|
||||
@@ -204,7 +204,8 @@ template <typename Stream, typename D>
|
||||
inline Stream& operator<<(Stream& s, DurationBase<D> d)
|
||||
{
|
||||
char buf[8];
|
||||
std::snprintf(buf, sizeof(buf), "%06lu", static_cast<unsigned long>(std::abs(d.toUSec() % 1000000L)));
|
||||
using namespace std; // For snprintf()
|
||||
snprintf(buf, sizeof(buf), "%06lu", static_cast<unsigned long>(std::abs(d.toUSec() % 1000000L)));
|
||||
if (d.isNegative())
|
||||
{
|
||||
s << '-';
|
||||
@@ -217,7 +218,8 @@ template <typename Stream, typename T, typename D>
|
||||
inline Stream& operator<<(Stream& s, TimeBase<T, D> t)
|
||||
{
|
||||
char buf[8];
|
||||
std::snprintf(buf, sizeof(buf), "%06lu", static_cast<unsigned long>(t.toUSec() % 1000000L));
|
||||
using namespace std; // For snprintf()
|
||||
snprintf(buf, sizeof(buf), "%06lu", static_cast<unsigned long>(t.toUSec() % 1000000L));
|
||||
s << (t.toUSec() / 1000000L) << '.' << buf;
|
||||
return s;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user