Skip to content

Commit 1f1b827

Browse files
committed
fixed boot_snprintf, and nanoprintf linking bugs
1 parent 12e83a1 commit 1f1b827

File tree

2 files changed

+27
-25
lines changed

2 files changed

+27
-25
lines changed

src/libc/boot_vsprintf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ int boot_vsnprintf(char *__restrict buffer, size_t count, const char *__restrict
2424
int boot_snprintf(char *__restrict buffer, size_t count, const char *__restrict format, ...) {
2525
va_list args;
2626
va_start(args, format);
27-
const int ret = vsnprintf(buffer, count, format, args);
27+
const int ret = boot_vsnprintf(buffer, count, format, args);
2828
va_end(args);
2929
return ret;
3030
}

src/libc/nanoprintf.c

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -982,15 +982,7 @@ int npf_vpprintf(npf_putc pc, void *pc_ctx, char const *format, va_list args) {
982982
#undef NPF_EXTRACT
983983
#undef NPF_WRITEBACK
984984

985-
int _printf_c(char const *format, ...) {
986-
va_list va;
987-
va_start(va, format);
988-
int const rv = vprintf(format, va);
989-
va_end(va);
990-
return rv;
991-
}
992-
993-
int _vsnprintf_c(char *buffer, size_t bufsz, char const *format, va_list vlist) {
985+
int _vsnprintf_c(char *__restrict buffer, size_t bufsz, char const *__restrict format, va_list vlist) {
994986
npf_bufputc_ctx_t bufputc_ctx;
995987
bufputc_ctx.dst = buffer;
996988
bufputc_ctx.len = bufsz;
@@ -1009,36 +1001,31 @@ int _vsnprintf_c(char *buffer, size_t bufsz, char const *format, va_list vlist)
10091001
return n;
10101002
}
10111003

1012-
int _snprintf_c(char *buffer, size_t bufsz, const char *format, ...) {
1004+
int _snprintf_c(char *__restrict buffer, size_t bufsz, const char *__restrict format, ...) {
10131005
va_list va;
10141006
va_start(va, format);
1015-
int const rv = vsnprintf(buffer, bufsz, format, va);
1007+
int const rv = _vsnprintf_c(buffer, bufsz, format, va);
10161008
va_end(va);
10171009
return rv;
10181010
}
10191011

1020-
int _vsprintf_c(char *buffer, const char *format, va_list vlist)
1012+
int _vsprintf_c(char *__restrict buffer, const char *__restrict format, va_list vlist)
10211013
{
1022-
return vsnprintf(buffer, (size_t)INT_MAX, format, vlist);
1023-
}
1024-
1025-
int _vprintf_c(const char *format, va_list vlist)
1026-
{
1027-
return npf_vpprintf(npf_putc_std, NULL, format, vlist);
1014+
return _vsnprintf_c(buffer, (size_t)INT_MAX, format, vlist);
10281015
}
10291016

1030-
int _sprintf_c(char *buffer, const char *format, ...)
1017+
int _sprintf_c(char *__restrict buffer, const char *__restrict format, ...)
10311018
{
10321019
va_list va;
10331020
va_start(va, format);
1034-
const int ret = vsnprintf(buffer, (size_t)INT_MAX, format, va);
1021+
const int ret = _vsnprintf_c(buffer, (size_t)INT_MAX, format, va);
10351022
va_end(va);
10361023
return ret;
10371024
}
10381025

10391026
int _vasprintf_c(char **__restrict p_str, const char *__restrict format, va_list vlist) {
10401027
*p_str = NULL;
1041-
int str_len = vsnprintf(NULL, 0, format, vlist);
1028+
int str_len = _vsnprintf_c(NULL, 0, format, vlist);
10421029
if (str_len <= 0) {
10431030
return str_len;
10441031
}
@@ -1048,7 +1035,7 @@ int _vasprintf_c(char **__restrict p_str, const char *__restrict format, va_list
10481035
// malloc failure
10491036
return -1;
10501037
}
1051-
int ret = vsnprintf(buf, buf_len, format, vlist);
1038+
int ret = _vsnprintf_c(buf, buf_len, format, vlist);
10521039
if (ret <= 0) {
10531040
free(buf);
10541041
return ret;
@@ -1060,11 +1047,12 @@ int _vasprintf_c(char **__restrict p_str, const char *__restrict format, va_list
10601047
int _asprintf_c(char **__restrict p_str, const char *__restrict format, ...) {
10611048
va_list va;
10621049
va_start(va, format);
1063-
const int ret = vasprintf(p_str, format, va);
1050+
const int ret = _vasprintf_c(p_str, format, va);
10641051
va_end(va);
10651052
return ret;
10661053
}
10671054

1055+
__attribute__((__always_inline__))
10681056
int _vfprintf_c(FILE* __restrict stream, const char* __restrict format, va_list vlist)
10691057
{
10701058
return npf_vpprintf(npf_fputc_std, (void*)stream, format, vlist);
@@ -1074,11 +1062,25 @@ int _fprintf_c(FILE* __restrict stream, const char* __restrict format, ...)
10741062
{
10751063
va_list va;
10761064
va_start(va, format);
1077-
const int ret = vfprintf(stream, format, va);
1065+
const int ret = _vfprintf_c(stream, format, va);
10781066
va_end(va);
10791067
return ret;
10801068
}
10811069

1070+
__attribute__((__always_inline__))
1071+
int _vprintf_c(const char *__restrict format, va_list vlist)
1072+
{
1073+
return npf_vpprintf(npf_putc_std, NULL, format, vlist);
1074+
}
1075+
1076+
int _printf_c(char const *__restrict format, ...) {
1077+
va_list va;
1078+
va_start(va, format);
1079+
int const rv = _vprintf_c(format, va);
1080+
va_end(va);
1081+
return rv;
1082+
}
1083+
10821084
#if NANOPRINTF_HAVE_GCC_WARNING_PRAGMAS
10831085
#pragma GCC diagnostic pop
10841086
#endif

0 commit comments

Comments
 (0)