mirror of https://github.com/ARMmbed/mbed-os.git
Using new rather than malloc in debug_print
Using malloc will require us to add stdlib.h somewhere in the path for the application. Maybe the CI apps are adding stdlib.h and that's why the code would have worked. In a custom app, it can happen that the header is not included. Using new avoids the need to add stdlib.h anywhere and it is more in line with C++.pull/10354/head
parent
65ada92527
commit
9229aba87d
|
@ -1289,7 +1289,7 @@ void ATHandler::debug_print(const char *p, int len, ATType type)
|
|||
#if MBED_CONF_CELLULAR_DEBUG_AT
|
||||
if (_debug_on) {
|
||||
const int buf_size = len * 4 + 1; // x4 -> reserve space for extra characters, +1 -> terminating null
|
||||
char *buffer = (char *)malloc(buf_size);
|
||||
char *buffer = new char [buf_size];
|
||||
if (buffer) {
|
||||
memset(buffer, 0, buf_size);
|
||||
|
||||
|
@ -1319,7 +1319,7 @@ void ATHandler::debug_print(const char *p, int len, ATType type)
|
|||
tr_info("AT ERR (%2d): %s", len, buffer);
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
delete [] buffer;
|
||||
} else {
|
||||
tr_error("AT trace unable to allocate buffer!");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue