Skip to content

Commit 70ef857

Browse files
[libunwind] Remove unnecessary dependencies on stdio.h for increased baremetal friendliness
1 parent e9de91e commit 70ef857

14 files changed

+146
-168
lines changed

libunwind/src/AddressSpace.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#define __ADDRESSSPACE_HPP__
1414

1515
#include <stdint.h>
16-
#include <stdio.h>
1716
#include <stdlib.h>
1817
#include <string.h>
1918

@@ -672,7 +671,10 @@ inline bool LocalAddressSpace::findFunctionName(pint_t addr, char *buf,
672671
Dl_info dyldInfo;
673672
if (dladdr((void *)addr, &dyldInfo)) {
674673
if (dyldInfo.dli_sname != NULL) {
675-
snprintf(buf, bufLen, "%s", dyldInfo.dli_sname);
674+
size_t nameLen = strlen(dyldInfo.dli_sname);
675+
size_t len = nameLen < (bufLen - 1) ? nameLen : (bufLen - 1);
676+
memcpy(buf, dyldInfo.dli_sname, len);
677+
buf[len] = '\0';
676678
*offset = (addr - (pint_t) dyldInfo.dli_saddr);
677679
return true;
678680
}
@@ -681,7 +683,9 @@ inline bool LocalAddressSpace::findFunctionName(pint_t addr, char *buf,
681683
uint16_t nameLen;
682684
char *funcName = getFuncNameFromTBTable(addr, nameLen, offset);
683685
if (funcName != NULL) {
684-
snprintf(buf, bufLen, "%.*s", nameLen, funcName);
686+
size_t len = nameLen < (bufLen - 1) ? nameLen : (bufLen - 1);
687+
memcpy(buf, funcName, len);
688+
buf[len] = '\0';
685689
return true;
686690
}
687691
#else

0 commit comments

Comments
 (0)