Bug 13486 - awk printf("%c", 0) doesn't print anything
Summary: awk printf("%c", 0) doesn't print anything
Status: RESOLVED FIXED
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: 1.33.x
Hardware: All Linux
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-01-26 22:10 UTC by alt.j2-4o4s2yon
Modified: 2021-06-04 07:45 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments
awk: allow printf('%c') to output NUL (2.99 KB, patch)
2021-01-27 11:18 UTC, Ron Yorston
Details

Note You need to log in before you can comment on or make changes to this bug.
Description alt.j2-4o4s2yon 2021-01-26 22:10:44 UTC
testcase:

echo -n "7F454C460201010000" | awk 'BEGIN{ht="123456789ABCDEF";}function h2i(h){return index(ht, substr(h,1,1))*16+index(ht,substr(h,2,1));} {for(i=1;i<=length($0);i+=2)printf("%c", h2i(substr($0,i,2)));}' | hexdump -ve '1/1 "%.2X"'

prints 7F454C460201010000 on gawk and mawk, busybox swallows the 2 null bytes at the end.
Comment 1 Ron Yorston 2021-01-27 11:18:00 UTC
Created attachment 8736 [details]
awk: allow printf('%c') to output NUL
Comment 2 alt.j2-4o4s2yon 2021-01-27 21:52:22 UTC
thanks ron for your patch. does it fix both printf and sprintf ?

btw looks like this has been reported once before: https://bugs.busybox.net/show_bug.cgi?id=12506
Comment 3 Ron Yorston 2021-01-27 22:12:02 UTC
The patch only fixes printf. As wolf+busybox says in the other bug, fixing sprintf is much harder. And you only asked for printf ;)