mirror of git://git.suckless.org/sbase
printf: handle \0 in %b arguments
The %b case was using fputs after unescape to print the argument, which meant that it could not handle nul bytes. Instead, store the length returned from unescape and use fwrite to properly handle them.
This commit is contained in:
parent
d6154bd87f
commit
123f784ccc
10
printf.c
10
printf.c
|
@ -19,7 +19,7 @@ int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
Rune *rarg;
|
Rune *rarg;
|
||||||
size_t i, j, argi, lastargi, formatlen;
|
size_t i, j, argi, lastargi, formatlen, blen;
|
||||||
long long num;
|
long long num;
|
||||||
double dou;
|
double dou;
|
||||||
int cooldown = 0, width, precision, ret = 0;
|
int cooldown = 0, width, precision, ret = 0;
|
||||||
|
@ -112,12 +112,12 @@ main(int argc, char *argv[])
|
||||||
case 'b':
|
case 'b':
|
||||||
if ((tmp = strstr(arg, "\\c"))) {
|
if ((tmp = strstr(arg, "\\c"))) {
|
||||||
*tmp = 0;
|
*tmp = 0;
|
||||||
unescape(arg);
|
blen = unescape(arg);
|
||||||
fputs(arg, stdout);
|
fwrite(arg, sizeof(*arg), blen, stdout);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
unescape(arg);
|
blen = unescape(arg);
|
||||||
fputs(arg, stdout);
|
fwrite(arg, sizeof(*arg), blen, stdout);
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
unescape(arg);
|
unescape(arg);
|
||||||
|
|
Loading…
Reference in New Issue