xref: /illumos-gate/usr/src/test/util-tests/tests/awk/gnu/uninit5.awk (revision 528737823843346cf95a4a701612f82089135554)
1#From gregfjohnson@yahoo.com  Sun Aug 30 08:36:36 2009
2#Return-Path: <gregfjohnson@yahoo.com>
3#Received: from aahz (localhost [127.0.0.1])
4#	by skeeve.com (8.14.1/8.14.1) with ESMTP id n7U5WoJ2003836
5#	for <arnold@localhost>; Sun, 30 Aug 2009 08:36:36 +0300
6#X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on server1.f7.net
7#X-Spam-Level:
8#X-Spam-Status: No, score=-6.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED
9#	autolearn=ham version=3.2.4
10#X-Envelope-From: gregfjohnson@yahoo.com
11#X-Envelope-To: <arnold@skeeve.com>
12#Received: from server1.f7.net [64.34.169.74]
13#	by aahz with IMAP (fetchmail-6.3.7)
14#	for <arnold@localhost> (single-drop); Sun, 30 Aug 2009 08:36:36 +0300 (IDT)
15#Received: from fencepost.gnu.org (fencepost.gnu.org [140.186.70.10])
16#	by f7.net (8.11.7-20030920/8.11.7) with ESMTP id n7U33m709453
17#	for <arnold@skeeve.com>; Sat, 29 Aug 2009 22:03:48 -0500
18#Received: from mail.gnu.org ([199.232.76.166]:42095 helo=mx10.gnu.org)
19#	by fencepost.gnu.org with esmtp (Exim 4.67)
20#	(envelope-from <gregfjohnson@yahoo.com>)
21#	id 1Mhai6-0004Qt-3R
22#	for bug-gawk@gnu.org; Sat, 29 Aug 2009 23:04:06 -0400
23#Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60)
24#	(envelope-from <gregfjohnson@yahoo.com>)
25#	id 1Mhai5-00062I-EM
26#	for bug-gawk@gnu.org; Sat, 29 Aug 2009 23:04:05 -0400
27#Received: from web33507.mail.mud.yahoo.com ([68.142.206.156]:28597)
28#	by monty-python.gnu.org with smtp (Exim 4.60)
29#	(envelope-from <gregfjohnson@yahoo.com>)
30#	id 1Mhai5-00061w-2n
31#	for bug-gawk@gnu.org; Sat, 29 Aug 2009 23:04:05 -0400
32#Received: (qmail 68722 invoked by uid 60001); 30 Aug 2009 03:04:03 -0000
33#DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1251601443; bh=9h2ZOOgxUh+s8Ow5/ZMWUxcviy2L4rpiaNamPAXxhEk=; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type; b=tWxCQq/aTOT5lhtdPc5hxtXzOjDFmLU6Ao0BSlwbeeBsd9Wl6DU3JCR4gTkoL0aVUOTdjMjgRY7I72yCht+YruDiqZrvtSKvUoAvZAKcPG26RE4jzxUlxQklEHZG9mq9h2gpTIiLYehYDiC0975wukwi/e7ePADfkFwg8eTnT44=
34#DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws;
35#  s=s1024; d=yahoo.com;
36#  h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type;
37#  b=LWfhVgxojFG1eYoRrxtrS3YOfH3MTUVTYZle/4utMQEPZQfsmrn6GBwBfThryGqJyZfg38/7JfK9cz/Q3Yt+mf8+xl9/m+Srckc+Xvi42CE0OmoN439vCyhAD8A74XOJsmfKDjJ/+LtioShStUohj1iYDDmRTN4RnnP9X4xnt3c=;
38#Message-ID: <410222.68490.qm@web33507.mail.mud.yahoo.com>
39#X-YMail-OSG: mfjax.MVM1lI2q5gcl6bChbn6zHgNgj1fByHWJSzB8ZZUmI2QCH6pNwV_IaHxcqecu.VqjKUR6HQhXbziUnX.v5E2nOE61ass9AzqfdVOtKTEAzTPQJ8Z7QB7fq7BMtjn8yohDR6mwOyVTqv3RZh0m1Us7sLit6UmcgeSvJo2rROAmeceq.FBwk2XnEp2_QsljjPHak_WXyvtAK81klDv5qQORWQWqR9q79x7yxORL6fLWwb_x6mZZMSOUaA0p8.ucT453eqT1L8NGkthF.fXmOM3_EYd03zUgr9Sb.zvMvbDC3MCMnVr0JT1uroLmFtVIdTojrFJYFQEDFSB9zT3Ua80ZpGXrjQGx3rZw--
40#Received: from [71.165.246.171] by web33507.mail.mud.yahoo.com via HTTP; Sat, 29 Aug 2009 20:04:03 PDT
41#X-Mailer: YahooMailClassic/6.1.2 YahooMailWebService/0.7.338.2
42#Date: Sat, 29 Aug 2009 20:04:03 -0700 (PDT)
43#From: Greg Johnson <gregfjohnson@yahoo.com>
44#Subject: bugs in passing uninitialized array to a function
45#To: bug-gawk@gnu.org
46#MIME-Version: 1.0
47#Content-Type: multipart/mixed; boundary="0-1690489838-1251601443=:68490"
48#X-detected-operating-system: by monty-python.gnu.org: FreeBSD 6.x (1)
49#Status: RO
50#
51#--0-1690489838-1251601443=:68490
52#Content-Type: text/plain; charset=us-ascii
53#
54#I am using gawk version 3.1.7.
55#
56#The attached programs illustrate what look to me like two bugs
57#in the handling of uninitialized variables to functions that treat
58#them as arrays.
59#
60#Greg Johnson
61#
62#
63#
64#--0-1690489838-1251601443=:68490
65#Content-Type: application/octet-stream; name=b1
66#Content-Transfer-Encoding: base64
67#Content-Disposition: attachment; filename="b1"
68
69# bug?  on uninitialized array, length(a) prints as 3, then the loop
70# behaves differently, iterating once.  so, length() behaves differently
71# on two calls to the same variable, which was not changed.
72
73function prt1(a, len)
74{
75    print "length:  " length(a)
76
77    for (i = 1; i <= length(a); i++)
78        printf "<" i "," a[i] "> "
79
80    print "\n"
81}
82
83BEGIN {
84    prt1(zzz)
85}
86
87#--0-1690489838-1251601443=:68490
88#Content-Type: application/octet-stream; name=b2
89#Content-Transfer-Encoding: base64
90#Content-Disposition: attachment; filename="b2"
91
92# shouldn't an uninitialized array have length zero?
93# length is printed as 1, and the loop iterates once.
94
95function prt(a, len)
96{
97    len = length(a)
98    print "length:  " len
99
100    for (i = 1; i <= len; i++)
101        printf "<" i "," a[i] "> "
102
103    print "\n"
104}
105
106BEGIN {
107    prt(zzz)
108}
109
110#--0-1690489838-1251601443=:68490--
111
112