mawk %d maxes out at 0x7FFFFFFF instead of 0xFFFFFFFF

Bug #1159933 reported by Martin Roth on 2013-03-25
20
This bug affects 4 people
Affects Status Importance Assigned to Milestone
mawk (Debian)
New
Unknown
mawk (Ubuntu)
Undecided
Unassigned

Bug Description

I'm honestly not sure if this is a bug or just an implementation decision, but it's different than gawk or original-awk, so I'm reporting it. This caused problems for coreboot which is using awk to calculate addresses up at the 0xFFFXXXXX range. We worked around it by using %.0f to print the values.

using the test:
   printf %u 0xFFFFFFFF | awk '{printf("%.0f %u %d", $1 , $1 , $1 )}'

mawk:
    4294967295 2147483647 2147483647

original-awk:
    4294967295 2147483648 4294967295

gawk:
    4294967295 4294967295 4294967295

I'm using ubuntu 12.04.02 LTS, and mawk 1.3.3-17.

On Mon, Mar 25, 2013 at 05:59:56PM -0000, Martin Roth wrote:
> Public bug reported:
>
> I'm honestly not sure if this is a bug or just an implementation
> decision, but it's different than gawk or original-awk, so I'm reporting
> it. This caused problems for coreboot which is using awk to calculate
> addresses up at the 0xFFFXXXXX range. We worked around it by using %.0f
> to print the values.
>
> using the test:
> printf %u 0xFFFFFFFF | awk '{printf("%.0f %u %d", $1 , $1 , $1 )}'
>
> mawk:
> 4294967295 2147483647 2147483647
>
> original-awk:
> 4294967295 2147483648 4294967295
>
> gawk:
> 4294967295 4294967295 4294967295

mawk 1.3.4 20130219 is different too, but call it an implementation decision.

+ mawk {printf("%.0f %u %d", $1 , $1 , $1 )}
+ printf %u 0xFFFFFFFF
4294967295 4294967295 2147483647

original-awk and gawk support some form of extended precision, but awk's
use types for data - so the treatment of unsigned values is likely where
you'll see the most (valid) variation. I recall fixing some issue which
is relevant to the handling of unsigned - 1.3.3's equating of the ranges
for %u and %d is arguably a bug.

--
Thomas E. Dickey <email address hidden>
http://invisible-island.net
ftp://invisible-island.net

Dave Spiegel (dave-spiegel) wrote :

I just ran into similar issue where using mawk (awk alternative) to format cksum values. Any value larger than 2G is truncated at 2G (2147483647). This is the same number Thomas is getting. Seems like mawk was built using older memory limitations?

Here is example (awk -> mawk:
$ cksum pin.sql.gz
3795651822 1865248 pin.sql.gz

$ cksum pin.sql.gz| awk '{printf ("%d", $1)}'
2147483647

Install gawk, and problem is gone (awk -> gawk).
$ cksum pin.sql.gz
3795651822 1865248 pin.sql.gz

$ cksum pin.sql.gz| awk '{printf ("%d", $1)}'
3795651822

Cunfirmed issue on two different Ubuntu server installs:
SERVER 1:
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=10.04
DISTRIB_CODENAME=lucid
DISTRIB_DESCRIPTION="Ubuntu 10.04.4 LTS"
mawk version 1.3.3-15ubuntu2
Linux 2.6.32-46-server #108-Ubuntu SMP Thu Apr 11 16:11:15 UTC 2013 x86_64 GNU/Linux

SERVER 2:
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04.2 LTS"
mawk version 1.3.3-17
Linux 3.2.0-41-generic #66-Ubuntu SMP Thu Apr 25 03:27:11 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

Did "apt-get install gawk" for both servers which replaced mawk alternative with gawk. Now our scripts work properly.

If this is bug, then it seems important to correct it. Perhaps mawk should not be default install on Ubuntu if it has bugs.

Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in mawk (Ubuntu):
status: New → Confirmed

As Thomas Dickey above says mawk 1.3.4 at least allows unsigned int values up to 4294967295.

Is there any reason the standard mawk package is stuck at 1.3.3? I have been using a compiled version of 1.3.4 and not only does it extend the range of unsigned ints but it also contains a number of bug fixes and executes about 30% faster on average.

On Thu, Nov 28, 2013 at 10:45:24PM -0000, Robert Thorneycroft wrote:
> As Thomas Dickey above says mawk 1.3.4 at least allows unsigned int
> values up to 4294967295.
>
> Is there any reason the standard mawk package is stuck at 1.3.3? I have

yes - it's a problem with the package maintainer.
See the Debian bug-reports for mawk to get context.

--
Thomas E. Dickey <email address hidden>
http://invisible-island.net
ftp://invisible-island.net

Mantas Kriaučiūnas (mantas) wrote :

mawk in Ubuntu and Debian is 18 years, see LP bug #1332114
I think this bug should be marked as duplicate of bug #1332114
Many bugs of Mawk are fixed in a new upstream versions 1.3.4-2010nnnn-2015nnnn, but the Debian maintainer does not want to update for an obscure reason.
We need to push here: http://bugs.debian.org/554167

Changed in mawk (Debian):
status: Unknown → New
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.