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