mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
remove a variable length stack allocated array and simplify builtin printf
This commit is contained in:
parent
34f2f77067
commit
3b4f4c5f59
1 changed files with 9 additions and 20 deletions
|
@ -365,22 +365,19 @@ void builtin_printf_state_t::print_direc(const wchar_t *start, size_t length, wc
|
||||||
bool have_precision, int precision,
|
bool have_precision, int precision,
|
||||||
wchar_t const *argument)
|
wchar_t const *argument)
|
||||||
{
|
{
|
||||||
wcstring fmt;
|
// Start with everything except the conversion specifier
|
||||||
|
wcstring fmt(start, length);
|
||||||
|
|
||||||
/* Create a null-terminated copy of the % directive, with an
|
/* Create a null-terminated copy of the % directive, with an
|
||||||
intmax_t-wide length modifier substituted for any existing
|
intmax_t-wide width modifier substituted for any existing
|
||||||
integer length modifier. */
|
integer length modifier. */
|
||||||
{
|
{
|
||||||
wchar_t *q;
|
// Append the appropriate width specifier
|
||||||
wchar_t const *length_modifier;
|
|
||||||
size_t length_modifier_len;
|
|
||||||
|
|
||||||
switch (conversion)
|
switch (conversion)
|
||||||
{
|
{
|
||||||
case L'd':
|
case L'd':
|
||||||
case L'i':
|
case L'i':
|
||||||
length_modifier = L"lld";
|
fmt.append(L"ll");
|
||||||
length_modifier_len = sizeof L"lld" - 2;
|
|
||||||
break;
|
break;
|
||||||
case L'a':
|
case L'a':
|
||||||
case L'e':
|
case L'e':
|
||||||
|
@ -390,26 +387,18 @@ void builtin_printf_state_t::print_direc(const wchar_t *start, size_t length, wc
|
||||||
case L'E':
|
case L'E':
|
||||||
case L'F':
|
case L'F':
|
||||||
case L'G':
|
case L'G':
|
||||||
length_modifier = L"L";
|
fmt.append(L"L");
|
||||||
length_modifier_len = 1;
|
|
||||||
break;
|
break;
|
||||||
case L's':
|
case L's':
|
||||||
case L'u':
|
case L'u':
|
||||||
length_modifier = L"l";
|
fmt.append(L"l");
|
||||||
length_modifier_len = 1;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
length_modifier = start; /* Any valid pointer will do. */
|
|
||||||
length_modifier_len = 0;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
wchar_t p[length + length_modifier_len + 2]; /* Null-terminated copy of % directive. */
|
// Append the conversion itself
|
||||||
q = wmemcpy(p, start, length) + length;
|
fmt.push_back(conversion);
|
||||||
q = wmemcpy(q, length_modifier, length_modifier_len) + length_modifier_len;
|
|
||||||
*q++ = conversion;
|
|
||||||
*q = L'\0';
|
|
||||||
fmt = p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (conversion)
|
switch (conversion)
|
||||||
|
|
Loading…
Reference in a new issue