Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 7 Sep 1999 21:03:43 +0800 (CST)
From:      Scott Hazen Mueller <scott@zorch.sf-bay.org>
To:        FreeBSD-gnats-submit@freebsd.org
Cc:        scott@zorch.sf-bay.org
Subject:   bin/13615: awk bug
Message-ID:  <199909071303.VAA12164@zorba.sf-bay.org>

next in thread | raw e-mail | index | archive | help

>Number:         13615
>Category:       bin
>Synopsis:       awk corrupts the memory arena when OFMT is not %.6g
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Sep  7 06:10:01 PDT 1999
>Closed-Date:
>Last-Modified:
>Originator:     Scott Hazen Mueller
>Release:        FreeBSD 3.2-RELEASE i386
>Organization:
none
>Environment:

	The code originates in C News, however all C News dependencies have been
    removed from the supplied test case.

>Description:

	When the supplied script is run against the supplied test data with
	OFMT unset or set to the default %.6g, the script completes normally.
    If OFMT is set to a value other than %.6g (values tested from %.7g to
    %.12g), the script generates numerous
    awk in free(): warning: chunk is already free.
    warnings.  Additionally, variable values change unexpectedly in apparent
    response to assignment of other variables.

    This is the output of a "normal" run:

 123123123123 1e+11
now0  123123123123 123123123123 1e+11                 <--- 1st checkpoint
now1  123123123123 0 1e+11
now2  123123123123 0 1e+11
123123123123 456456456456 1e+11
now0  456456456456 456456456456 1e+11                 <--- 2nd checkpoint
now1  456456456456 0 1e+11
now2  456456456456 0 1e+11
456456456456 789789789789 1e+11
now0  789789789789 789789789789 1e+11                 <--- 3rd checkpoint
now1  789789789789 0 1e+11
now2  789789789789 0 1e+11

   This is the output when OFMT is %.7g:

 1.231231e+11 1e+11
awk in free(): warning: chunk is already free.
now0  123123123123 1e+11 1e+11                        <--- 1st checkpoint
awk in free(): warning: chunk is already free.
now1  123123123123 1e+11 1e+11
now2  123123123123 1e+11 1e+11
awk in free(): warning: chunk is already free.
123123123123 4.564564e+11 4.564564e+11
now0  456456456456 456456456456 456456456456          <--- 2nd checkpoint
awk in free(): warning: chunk is already free.
awk in free(): warning: chunk is already free.
now1  0 0 0                                           <--- error
awk in free(): warning: chunk is already free.
awk in free(): warning: chunk is already free.
now2  0 0 0
awk in free(): warning: chunk is already free.
awk in free(): warning: chunk is already free.
7.897898e+11 7.897898e+11 7.897898e+11                <--- 3rd checkpoint       awk in free(): warning: chunk is already free.
awk in free(): warning: chunk is already free.
now1  6.653991e-316 6.653991e-316 6.653991e-316       <--- error
awk in free(): warning: chunk is already free.
awk in free(): warning: chunk is already free.
now2  9.999994e+10 9.999994e+10 9.999994e+10

    Note that in the second output set, the variable values went to '0 0 0'
    between the 2nd and 3rd checkpoint, and went to 6.65e-316 after the 3rd
    checkpoint.  These output lines are indicated with 'error'.

>How-To-Repeat:

    awk script:

BEGIN {
OFMT = "%.7g"
#OFMT = "%.6g"
big = 99999999999
lowest = big
small = 0
highest = small
dir = ""
}
        {
                if ($1 < lowest)
                        lowest = $1
                if ($1 > highest)
                        highest = $1

                        print dir, highest, lowest
                dir = $0
print "now0 ", dir, highest, lowest
                highest = small
print "now1 ", dir, highest, lowest
                lowest = big
print "now2 ", dir, highest, lowest
        }

input file:
123123123123
456456456456
789789789789

    Execute awk -f script <input
    To see the normal case, uncomment 'OFMT="%.6g"'.
    Note on the script - the seemingly meaningless tests and assignments
    are necessary to reproduce the error condition.  This is the simplest
    script I could generate that reproduced the failure.

>Fix:
	
    Setting OFMT to %.6g seems to cause normal behavior, at the loss of
    flexibility in formatting the output.


>Release-Note:
>Audit-Trail:
>Unformatted:


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199909071303.VAA12164>