Bug 15041

Summary: [PATCH] Awk: fix printf format when using large numbers
Product: Busybox Reporter: Carlos Ibáñez <caribpa>
Component: OtherAssignee: unassigned
Status: NEW ---    
Severity: normal CC: busybox-cvs
Priority: P5    
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Host: Target:
Build:
Attachments: awk-printf-fix-format-large-numbers.patch

Description Carlos Ibáñez 2022-10-08 18:52:16 UTC
Created attachment 9381 [details]
awk-printf-fix-format-large-numbers.patch

Hi!

I noticed that Busybox awk truncates double to int when printing as %d, %i, %u, %o, or %x [1][2]. This means that expected information is lost, for example:

  awk 'BEGIN{printf "0x%x\n", 4294967290}'

returns 0x80000000 (or 0x7fffffff in some platforms) instead of 0xfffffffa, like it happens in at least gawk, mawk, and nawk.

The patch attached simply changes the int casting into long long and removes the TODO comment.

Cheers,
Carlos


[1] - https://git.busybox.net/busybox/tree/editors/awk.c?id=c8c1fcdba163f264a503380bc63485aacd09214c#n929
[2] - https://git.busybox.net/busybox/tree/editors/awk.c?id=c8c1fcdba163f264a503380bc63485aacd09214c#n2418