Your message dated Mon, 10 Feb 2020 17:14:44 -0500
with message-id <[email protected]>
and subject line Re: Bug#950894: Acknowledgement (mawk: numeric comparison on 
'sub()' resulted ${n} vars does not work properly)
has caused the Debian Bug report #950894,
regarding mawk: numeric comparison on 'sub()' resulted ${n} vars does not work 
properly
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact [email protected]
immediately.)


-- 
950894: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=950894
Debian Bug Tracking System
Contact [email protected] with problems
--- Begin Message ---
Package: mawk
Version: 1.3.3-17+b3
Severity: normal

Dear Maintainer,

NOTE: this affects both 'mawk' and 'gawk' equally, so i'm not sure if this is 
some utterly esoteric behavior i'm just not "getting", but my expectations are 
definitely not being met.
(i also am unaware if a bug can be co-assigned to different packages)

Attempting to do a search for filesystems > 90% inode % or size % was giving 
anomolous results. (hair-pulling time)

I was using 'sub("%","",$1) to strip the % symbol off the results from:
    df --output=ipcent,pcent,target /var /var/log
e.g.:
    $ df --output=ipcent,pcent,target -t ext4  | mawk 
'NR>1{sub("%","",$1);sub("%","",$2); if (($1>30)||($2>30)) print}'
    40 79 /
    6 30 /var
    1 7 /opt
    20 78 /home
    1 89 /d1
(clearly /opt doesn't meet the reporting criteria)

I narrowed this down to what appears to be a field-size truncation comparison 
issue with the result from the sub() against the comparison numeric on the 
right-side of the relop:

# The following all work as expected: (no output)
$ for i in $(seq 20 29); do echo "$i%" | mawk '{if (int($1)>100) print}'; done
$ for i in $(seq 20 29); do echo "$i%" | gawk '{if (int($1)>100) print}'; done
$ for i in $(seq 20 29); do echo "$i%" | mawk '{if (($1+0)>100) print}'; done
$ for i in $(seq 20 29); do echo "$i%" | gawk '{if (($1+0)>100) print}'; done

This does NOT work, though it should: (none of these values should print, they 
are all < 100, which is the comparison being made)
$ for i in $(seq 20 29); do echo "$i%" | mawk '{sub("%","",$1);if ($1>100) 
printf("[%s][%d]\n",$1,$1)}'; done
[20][20]
[21][21]
[22][22]
[23][23]
[24][24]
[25][25]
[26][26]
[27][27]
[28][28]
[29][29]

The man pages clearly state that a dual-type (numeric&string) variable SHOULD 
be implicitly cast to numeric if a comparison is against a numeric.

I also did this against a single digit input and a two-digit RHS value, and it 
shows the same issue, where only the same number of digits of the RHS that the 
input value contain are being compared.
$ for i in $(seq 0 20); do echo "$i%" | gawk '{sub("%","",$1);if ($1>40) 
printf("[%s][%d]\n",$1,$1)}'; done
[5][5]
[6][6]
[7][7]
[8][8]
[9][9]

Using an RHS of a float also fails:
$ for i in $(seq 0 20); do echo "$i%" | gawk '{sub("%","",$1);if ($1>40.0) 
printf("[%s][%d]\n",$1,$1)}'; done
[5][5]
[6][6]
[7][7]
[8][8]
[9][9]

I don't know how if there's a way to evaluate the internal data-type 
representation for $1 here, so i printed it with printf both as string and 
integer, and they report identical.

Thanks,
--stephen


-- System Information:
Debian Release: 10.2
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'proposed-updates'), (500, 
'stable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 4.19.0-7-amd64 (SMP w/16 CPU cores)
Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_OOT_MODULE, 
TAINT_UNSIGNED_MODULE
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE= 
(charmap=UTF-8)
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages mawk depends on:
ii  libc6  2.28-10

mawk recommends no packages.

mawk suggests no packages.

-- no debconf information

--- End Message ---
--- Begin Message ---
Version: 1.3.3-17

On Sat, 8 Feb 2020 12:33:20 -0700 Stephen Dowdy <[email protected]> wrote:
> Considered this closed.  Communication on '[email protected]' indicates that
'sub()' modifies a 'strnum' to a 'string' for $1, and that it is no longer
considered "user input", but a string constant, and thus comparisons will be
done as string only.
> 
> Ref: https://www.gnu.org/software/gawk/manual/html_node/Variable-Typing.html

Closing the bug per the bug submitter's request.

-- 
Thanks,
Boyuan Yang

Attachment: signature.asc
Description: This is a digitally signed message part


--- End Message ---

Reply via email to