Bug 15041 - [PATCH] Awk: fix printf format when using large numbers
Summary: [PATCH] Awk: fix printf format when using large numbers
Status: NEW
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: unspecified
Hardware: All All
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-10-08 18:52 UTC by Carlos Ibáñez
Modified: 2022-10-08 18:52 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments
awk-printf-fix-format-large-numbers.patch (794 bytes, patch)
2022-10-08 18:52 UTC, Carlos Ibáñez
Details

Note You need to log in before you can comment on or make changes to this bug.
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