xref: /illumos-gate/usr/src/test/util-tests/tests/awk/gnu/strnum1.awk (revision e6d6c189fa3a95d7aa27bbe0aeacf7c1a6b57c8c)
1*e6d6c189SCody Peter Mello# Date: Tue, 04 Jul 2006 21:06:14 +0200 (MEST)
2*e6d6c189SCody Peter Mello# From: Heiner Marxen <Heiner.Marxen@DrB.Insel.DE>
3*e6d6c189SCody Peter Mello# Subject: conversion error
4*e6d6c189SCody Peter Mello# To: bug-gawk@gnu.org
5*e6d6c189SCody Peter Mello# Message-id: <200607041906.k64J6Eqa019360@drb9.drb.insel.de>
6*e6d6c189SCody Peter Mello#
7*e6d6c189SCody Peter Mello# Hello,
8*e6d6c189SCody Peter Mello#
9*e6d6c189SCody Peter Mello# The following awk script fails for gawk 3.1.4 and 3.1.5.
10*e6d6c189SCody Peter Mello# Older versions did not do this, but I cannot say, how old they were.
11*e6d6c189SCody Peter Mello#
12*e6d6c189SCody Peter MelloBEGIN {
13*e6d6c189SCody Peter Mello    if( 0 ) {		#ok
14*e6d6c189SCody Peter Mello	t = "8"
15*e6d6c189SCody Peter Mello    }else {		#fails
16*e6d6c189SCody Peter Mello	t = ""
17*e6d6c189SCody Peter Mello	t = t "8"
18*e6d6c189SCody Peter Mello    }
19*e6d6c189SCody Peter Mello    printf("8  = %d\n", 0+t)	# ok without this line
20*e6d6c189SCody Peter Mello    t = t "8"			# does not invalidate numeric interpretation
21*e6d6c189SCody Peter Mello    printf("88 = %s\n", 0+t)
22*e6d6c189SCody Peter Mello    ## The above prints "88 = 8" with gawk 3.1.4 and 3.1.5
23*e6d6c189SCody Peter Mello}
24*e6d6c189SCody Peter Mello#
25*e6d6c189SCody Peter Mello#
26*e6d6c189SCody Peter Mello# The following one-liner already exhibits the bug:
27*e6d6c189SCody Peter Mello#
28*e6d6c189SCody Peter Mello# gawk 'BEGIN{t=""; t=t "8";printf("8=%d\n", 0+t);t=t "8";printf("88=%s\n", 0+t)}'
29*e6d6c189SCody Peter Mello#
30*e6d6c189SCody Peter Mello#
31*e6d6c189SCody Peter Mello# Preliminary observation: under somewhat strange conditions a variable
32*e6d6c189SCody Peter Mello# does retain its numeric interpretation although something is appended to it.
33*e6d6c189SCody Peter Mello# --
34*e6d6c189SCody Peter Mello# Heiner Marxen				http://www.drb.insel.de/~heiner/
35*e6d6c189SCody Peter Mello#
36