Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

user/3359: m4 treats bitwise operations in eval as logical operations

From: <flag(at)pobox.se>
Date: Fri Jul 18 2003 - 09:57:07 EDT


>Number: 3359
net
>Environment:
        

	System      : OpenBSD 3.3
	Architecture: OpenBSD.i386
	Machine     : i386

>Description:
he operators "&" and "&&" are treated the same way, as logical-and, when "&" should be bitwise-and. The same is true for "|" and "||".
>How-To-Repeat:
for bitwise and: prompt$ echo "eval(224&127)" | m4 should return 96 but return 1 for bitwise or: prompt$ echo "eval(224|127)" | m4 should return 255 but return 1
>Fix:
I don't know if this breaks a lot of other things, but it fixes the bitwise problem.

Index: expr.c



RCS file: /cvs/src/usr.bin/m4/expr.c,v
retrieving revision 1.15
diff -u -r1.15 expr.c
--- expr.c      3 Jun 2003 02:56:10 -0000       1.15
+++ expr.c      18 Jul 2003 13:55:57 -0000
@@ -187,10 +187,14 @@  
        vl = land();
        while ((c = skipws()) == '|') {
-               if (getch() != '|')
-                       ungetch();
+           if (getch() != '|') {
+               ungetch();
+               vr = land();
+               vl = vl | vr;
+           } else {
                vr = land();
                vl = vl || vr;
+           }
        }
 
        ungetch();

@@ -207,12 +211,15 @@  
        vl = not();
        while ((c = skipws()) == '&') {
-               if (getch() != '&')
-                       ungetch();
+           if (getch() != '&') {
+               ungetch();
+               vr = not();
+               vl = vl & vr;
+           } else {
                vr = not();
                vl = vl && vr;
+           }
        }
-
        ungetch();
        return vl;

 }

>Release-Note:
Received on Fri Jul 18 10:34:03 2003

This archive was generated by hypermail 2.1.8 : Wed Aug 23 2006 - 13:30:00 EDT


Contact Us  Legal Notices  Order Services Online 
Pantek Home  Privacy Policy  IT news  Site Map  Pantek Library