Skip to content

Removed a number of compiler warnings. #483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions cores/arduino/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,33 @@ size_t Print::printFloat(double number, uint8_t digits)

return n;
}

size_t Print::printf(const char *format, ...)
{
char loc_buf[64];
char* temp = loc_buf;
va_list arg;
va_list copy;
va_start(arg, format);
va_copy(copy, arg);
int len = vsnprintf(temp, sizeof(loc_buf), format, copy);
va_end(copy);
if (len < 0) {
va_end(arg);
return 0;
}
if (len >= (int)sizeof(loc_buf)) {
temp = (char*)malloc(len + 1);
if (temp == NULL) {
va_end(arg);
return 0;
}
len = vsnprintf(temp, len + 1, format, arg);
}
va_end(arg);
len = write((uint8_t*)temp, len);
if (temp != loc_buf) {
free(temp);
}
return len;
}
2 changes: 2 additions & 0 deletions cores/arduino/Print.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class Print
size_t print(double, int = 2);
size_t print(const Printable&);

size_t printf(const char * format, ...) __attribute__ ((format (printf, 2, 3)));

size_t println(const __FlashStringHelper *);
size_t println(const String &s);
size_t println(const char[]);
Expand Down
8 changes: 4 additions & 4 deletions cores/arduino/new.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void * operator new[](std::size_t size) {
return operator new(size);
}

void * operator new(std::size_t size, const std::nothrow_t tag) noexcept {
void * operator new(std::size_t size, const std::nothrow_t) noexcept {
#if defined(NEW_TERMINATES_ON_FAILURE)
// Cannot call throwing operator new as standard suggests, so call
// new_helper directly then
Expand All @@ -65,7 +65,7 @@ void * operator new(std::size_t size, const std::nothrow_t tag) noexcept {
return operator new(size);
#endif
}
void * operator new[](std::size_t size, const std::nothrow_t& tag) noexcept {
void * operator new[](std::size_t size, const std::nothrow_t&) noexcept {
#if defined(NEW_TERMINATES_ON_FAILURE)
// Cannot call throwing operator new[] as standard suggests, so call
// malloc directly then
Expand Down Expand Up @@ -100,10 +100,10 @@ void operator delete[](void * ptr, std::size_t size) noexcept {
}
#endif // __cplusplus >= 201402L

void operator delete(void* ptr, const std::nothrow_t& tag) noexcept {
void operator delete(void* ptr, const std::nothrow_t&) noexcept {
operator delete(ptr);
}
void operator delete[](void* ptr, const std::nothrow_t& tag) noexcept {
void operator delete[](void* ptr, const std::nothrow_t&) noexcept {
operator delete[](ptr);
}

Expand Down