- Added @format attribute for compile time printf validation #2057.

- Bug when printing a boolean value as an integer using printf.
This commit is contained in:
Christoffer Lerno
2025-03-24 13:32:44 +01:00
parent 50d7919fec
commit d760378b02
10 changed files with 186 additions and 8 deletions

View File

@@ -52,7 +52,7 @@ fn uint128? int_from_any(any arg, bool *is_neg) @private
switch (arg.type)
{
case bool:
return *(uint128*)arg;
return (uint128)*(bool*)arg;
case ichar:
int val = *(ichar*)arg;
return (*is_neg = val < 0) ? (~(uint128)val) + 1 : (uint128)val;

View File

@@ -139,7 +139,7 @@ macro usz? fprint(out, x)
@param [in] format : `The printf-style format string`
@return `the number of characters printed`
*>
fn usz? fprintf(OutStream out, String format, args...)
fn usz? fprintf(OutStream out, String format, args...) @format(1)
{
Formatter formatter;
formatter.init(&out_putstream_fn, &out);
@@ -154,7 +154,7 @@ fn usz? fprintf(OutStream out, String format, args...)
@param [in] format : `The printf-style format string`
@return `the number of characters printed`
*>
fn usz? fprintfn(OutStream out, String format, args...) @maydiscard
fn usz? fprintfn(OutStream out, String format, args...) @format(1) @maydiscard
{
Formatter formatter;
formatter.init(&out_putstream_fn, &out);
@@ -249,7 +249,7 @@ fn void? out_putchar_fn(void* data @unused, char c) @private
@param [in] format : `The printf-style format string`
@return `the number of characters printed`
*>
fn usz? printf(String format, args...) @maydiscard
fn usz? printf(String format, args...) @format(0) @maydiscard
{
Formatter formatter;
formatter.init(&out_putchar_fn);
@@ -263,7 +263,7 @@ fn usz? printf(String format, args...) @maydiscard
@param [in] format : `The printf-style format string`
@return `the number of characters printed`
*>
fn usz? printfn(String format, args...) @maydiscard
fn usz? printfn(String format, args...) @format(0) @maydiscard
{
Formatter formatter;
formatter.init(&out_putchar_fn);