[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [BusyBox] awk bug.
From:       David Updegraff <dave () cray ! com>
Date:       2003-04-29 16:58:51
[Download RAW message or body]

Hi.

I noticed that awk's field parameters were broken when cross
compiling busybox from Solaris to soft-float ppc405.
	# echo 1 2 3 | awk '{print $2}'
	1

Somehow, this does not happen when the cross compile is hosted
on linux-x86.. but anyway, its a bug in awk: a double is cast
to an int, value is lost.  I don't know that the offical doctrine
is to convert a double to an int, but I don't think its just i=(int)d.

Anyway, enlcosed patch fixes it.

Thanx for assistance.

-- 
Dave Updegraff / dave@cray.com / 218-525-1154

["awk.patch" (text/plain)]

Index: editors/awk.c
===================================================================
RCS file: /var/cvs/busybox/editors/awk.c,v
retrieving revision 1.4
diff -u -r1.4 awk.c
--- editors/awk.c	19 Mar 2003 09:11:45 -0000	1.4
+++ editors/awk.c	29 Apr 2003 17:01:00 -0000
@@ -2424,7 +2424,11 @@
 			break;
 
 		  case XC( OC_FIELD ):
-		  	R.i = (int)getvar_i(R.v);
+			/* DBU:[dave@cray.com] casting double to int is wrong way to
+			 * get int value!  Breaks on some cross-compilers.
+		  	 * R.i = (int)getvar_i(R.v);
+			 */
+		  	R.i = (int)lrint(getvar_i(R.v));
 		  	if (R.i == 0) {
 				res = V[F0];
 			} else {


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic