static void
verify_numeric (char const *s, char const *end)
{
- if (errno)
+ if (s == end)
+ {
+ error (0, 0, _("%s: expected a numeric value"), quote (s));
+ exit_status = EXIT_FAILURE;
+ }
+ else if (errno)
{
error (0, errno, "%s", quote (s));
exit_status = EXIT_FAILURE;
}
else if (*end)
{
- if (s == end)
- error (0, 0, _("%s: expected a numeric value"), quote (s));
- else
- error (0, 0, _("%s: value not completely converted"), quote (s));
+ error (0, 0, _("%s: value not completely converted"), quote (s));
exit_status = EXIT_FAILURE;
}
}
case 'd':
case 'i':
{
- intmax_t arg = vstrtoimax (argument);
+ intmax_t arg = argument ? vstrtoimax (argument) : 0;
if (!have_field_width)
{
if (!have_precision)
case 'x':
case 'X':
{
- uintmax_t arg = vstrtoumax (argument);
+ uintmax_t arg = argument ? vstrtoumax (argument) : 0;
if (!have_field_width)
{
if (!have_precision)
case 'g':
case 'G':
{
- long double arg = vstrtold (argument);
+ long double arg = argument ? vstrtold (argument) : 0;
if (!have_field_width)
{
if (!have_precision)
break;
case 'c':
- if (!have_field_width)
- xprintf (p, *argument);
- else
- xprintf (p, field_width, *argument);
+ {
+ char c = argument ? *argument : '\0';
+ if (!have_field_width)
+ xprintf (p, c);
+ else
+ xprintf (p, field_width, c);
+ }
break;
case 's':
+ if (!argument)
+ argument = "";
if (!have_field_width)
{
if (!have_precision)
print_direc (direc, *ac.f,
have_field_width, field_width,
have_precision, precision,
- argc <= ac.curr_arg ? "" : argv[ac.curr_arg]);
+ ac.curr_arg < argc ? argv[ac.curr_arg] : nullptr);
break;
$prog '11 %*c\n' 2 x >>out || fail=1
+returns_ 1 $prog '12 %*s\n' '' 'empty width' >>out 2>/dev/null || fail=1
+returns_ 1 $prog '13 %*s\n' ' ' 'space width' >>out 2>/dev/null || fail=1
+returns_ 1 $prog '14 %.*sx\n' '' 'empty precision' >>out 2>/dev/null || fail=1
+returns_ 1 $prog '15 %.*sx\n' ' ' 'space precision' >>out 2>/dev/null || fail=1
+
returns_ 1 $prog '%#d\n' 0 >>out 2> /dev/null || fail=1
returns_ 1 $prog '%0s\n' 0 >>out 2> /dev/null || fail=1
9 0 x
10 0x
11 x
+12 empty width
+13 space width
+14 x
+15 x
EOF
compare exp out || fail=1