1. ver 4.0 found the BUG in WIN98 code

 
-- This is a simple program that shows demonstrates the BUG. 
-- 
-- If you run the following program using WIN2000 ver 4.0 binaries or 
-- the WIN98 ver 3.11 binaries. 
-- The ? [$] and the printf both print the same value. 
-- 
-- If you run the same code using WIN98 ver 4.0 binaries then the 
-- ? [$] and the printf DIFFERENT values. 
-- 
-- Of course you have to use include dll.e on the WIN98 ver 3.11 binaries. 
 
-- Start junk.exw ------------------------------------------------------------   
 
include std/dll.e 
 
sequence x 
 
function foo(sequence n) 
n &= define_c_var(open_dll("user32.dll"),n) 
? n[$] 
if n[$] then return sprintf(" %d ",{n[$]}) end if 
end function 
 
x = foo("MessageBeep") 
 
printf(1,x,{}) 
 
if getc(0) then end if 
 
-- End junk.exw ------------------------------------------------------------   
 
new topic     » topic index » view message » categorize

2. Re: ver 4.0 found the BUG in WIN98 code

bernie said...
-- If you run the same code using WIN98 ver 4.0 binaries then the 
-- ? [$] and the printf DIFFERENT values. 

What output are you getting? And what were you expecting?

Here's what I get when I run your code (both with 3.1.1 and 4.0.r1212):

2118328187 
 2118328187 

Matt

new topic     » goto parent     » topic index » view message » categorize

3. Re: ver 4.0 found the BUG in WIN98 code

bernie said...
 
-- This is a simple program that shows demonstrates the BUG. 
-- 
-- If you run the following program using WIN2000 ver 4.0 binaries or 
-- the WIN98 ver 3.11 binaries. 
-- The ? [$] and the printf both print the same value. 
-- 
-- If you run the same code using WIN98 ver 4.0 binaries then the 
-- ? [$] and the printf DIFFERENT values. 
-- 
-- Of course you have to use include dll.e on the WIN98 ver 3.11 binaries. 
 
-- Start junk.exw ------------------------------------------------------------   
 
include std/dll.e 
 
sequence x 
 
function foo(sequence n) 
n &= define_c_var(open_dll("user32.dll"),n) 
? n[$] 
if n[$] then return sprintf(" %d ",{n[$]}) end if 
end function 
 
x = foo("MessageBeep") 
 
printf(1,x,{}) 
 
if getc(0) then end if 
 
-- End junk.exw ------------------------------------------------------------   
 

This is what I get on WIN98 machine running WIN98 binaries.

3217040639
-2147483648

new topic     » goto parent     » topic index » view message » categorize

4. Re: ver 4.0 found the BUG in WIN98 code

bernie said...

This is what I get on WIN98 machine running WIN98 binaries.

3217040639
-2147483648

Could you try using the %x, %g and %f formats? Maybe also try poking it into memory, and peeking it out to see what it looks like. Since the '?' operator seems to give the correct result,

This value is suspicious, because the -2147483648 is 0x80000000, which is the mask that euphoria uses to identify a sequence.

I'm on XP, and I haven't found a way to duplicate this (it's a build with MANAGED_MEM turned on, BTW).

Matt

new topic     » goto parent     » topic index » view message » categorize

5. Re: ver 4.0 found the BUG in WIN98 code

mattlewis said...
bernie said...

This is what I get on WIN98 machine running WIN98 binaries.

3217040639
-2147483648

Could you try using the %x, %g and %f formats? Maybe also try poking it into memory, and peeking it out to see what it looks like. Since the '?' operator seems to give the correct result,

This value is suspicious, because the -2147483648 is 0x80000000, which is the mask that euphoria uses to identify a sequence.

I'm on XP, and I haven't found a way to duplicate this (it's a build with MANAGED_MEM turned on, BTW).

Matt

%x returns
3217040639
80000000

%g returns
3217040639
3.21704e+09

%f returns
3217040639
3217040639.000000

new topic     » goto parent     » topic index » view message » categorize

6. Re: ver 4.0 found the BUG in WIN98 code

bernie said...

%x returns
3217040639
80000000

%g returns
3217040639
3.21704e+09

%f returns
3217040639
3217040639.000000

Looks like something is happening in sprintf.

Matt

new topic     » goto parent     » topic index » view message » categorize

7. Re: ver 4.0 found the BUG in WIN98 code

mattlewis said...
bernie said...

%x returns
3217040639
80000000

%g returns
3217040639
3.21704e+09

%f returns
3217040639
3217040639.000000

Looks like something is happening in sprintf.

Matt

 
-- It has to be there because this code does the same thing. 
 
include std/memory.e 
 
sequence x 
 
x = sprintf(" %d ",{3217040639}) 
printf(1,x,{}) 
 
if getc(0) then end if 
 
new topic     » goto parent     » topic index » view message » categorize

8. Re: ver 4.0 found the BUG in WIN98 code

bernie said...
 
-- It has to be there because this code does the same thing. 
 
include std/memory.e 
 
sequence x 
 
x = sprintf(" %d ",{3217040639}) 
printf(1,x,{}) 
 
if getc(0) then end if 
 

Ok, now we just have to track down where the problem is occurring. Since I can't reproduce it, I'll need your help to figure this out. I think we should focus on FormatItem() in be_runtime.c. And on the v_elem parameter in particular. Here's what I'd like you to do:

be_runtime.c said...

// line 3940: (before cstring[flen++] = c;) 
printf("v_elem: %08x, dval: %08x\ngval: %.0f\n", *v_elem, dval, gval ); 

And then let me know what you get.

Matt

new topic     » goto parent     » topic index » view message » categorize

9. Re: ver 4.0 found the BUG in WIN98 code

mattlewis said...
be_runtime.c said...

// line 3940: (before cstring[flen++] = c;) 
printf("v_elem: %08x, dval: %08x\ngval: %.0f\n", *v_elem, dval, gval ); 

And then let me know what you get.

Matt

Matt: When I compile with that line I get filesys.obj error. Do I need some include added to be_runtime.c file.

new topic     » goto parent     » topic index » view message » categorize

10. Re: ver 4.0 found the BUG in WIN98 code

bernie said...
mattlewis said...
be_runtime.c said...

// line 3940: (before cstring[flen++] = c;) 
printf("v_elem: %08x, dval: %08x\ngval: %.0f\n", *v_elem, dval, gval ); 

And then let me know what you get.

Matt: When I compile with that line I get filesys.obj error. Do I need some include added to be_runtime.c file.

The filesys.obj error doesn't make sense to me. Something else is causing that. I'd suggest cleaning the build and starting over.

Matt

new topic     » goto parent     » topic index » view message » categorize

11. Re: ver 4.0 found the BUG in WIN98 code

be_runtime.c said...

// line 3940: (before cstring[flen++] = c;) 
printf("v_elem: %08x, dval: %08x\ngval: %.0f\n", *v_elem, dval, gval ); 

That sysobj error was just a compiler burp. I ran again and it went away.

I put the printf statement in the be_runtime.c but when I ran the
program nothing printed out.

I also tried fprintf to stderr still nothing so thats not where it's happening.

new topic     » goto parent     » topic index » view message » categorize

12. Re: ver 4.0 found the BUG in WIN98 code FOUND PROBLEM

Matt: I see what the problem is; It is caused by the dval.
The #80000000 is the limit of a long integer.
What we need in Euphoria is a sprintf with %u specifier parameter.

new topic     » goto parent     » topic index » view message » categorize

13. Re: ver 4.0 found the BUG in WIN98 code FOUND PROBLEM

bernie said...

Matt: I see what the problem is; It is caused by the dval.
The #80000000 is the limit of a long integer.
What we need in Euphoria is a sprintf with %u specifier parameter.

Matt: Look at the code that converts gval for a long integer by
changing it to float.
Could you do the same thing with dval?

new topic     » goto parent     » topic index » view message » categorize

14. Re: ver 4.0 found the BUG in WIN98 code FOUND PROBLEM

bernie said...

Matt: I see what the problem is; It is caused by the dval.
The #80000000 is the limit of a long integer.
What we need in Euphoria is a sprintf with %u specifier parameter.

I don't think that's the problem. Because if the number were that big, euphoria would store it as a double. For euphoria code, there's not really such thing as signed and unsigned. Everything is signed, and and atom is automatically promoted to a double if the magnitude grows too much.

What happens if you try:

   atom a = n[$] 
   print(1, "a %d\n", a ) 
   print(1, "a %d\n", {a} ) 
   ? {n[$]} 
   ? {a} 

Matt

new topic     » goto parent     » topic index » view message » categorize

15. Re: ver 4.0 found the BUG in WIN98 code FOUND PROBLEM

mattlewis said...
bernie said...

Matt: I see what the problem is; It is caused by the dval.
The #80000000 is the limit of a long integer.
What we need in Euphoria is a sprintf with %u specifier parameter.

I don't think that's the problem. Because if the number were that big, euphoria would store it as a double. For euphoria code, there's not really such thing as signed and unsigned. Everything is signed, and and atom is automatically promoted to a double if the magnitude grows too much.

What happens if you try:

   atom a = n[$] 
   print(1, "a %d\n", a ) 
   print(1, "a %d\n", {a} ) 
   ? {n[$]} 
   ? {a} 

Matt:
I actually used rtfatal to sprintf a buffer and I looked at dval
when the program crashed and the the dval was #80000000.
That is -2147483648 which is the the lower limit of long(signed).
It does not return that on win2000 because the long integer may have
different limits. And ver 3.11 may work because the compiled code
never uses memory at those large memory values.

new topic     » goto parent     » topic index » view message » categorize

16. Re: ver 4.0 found the BUG in WIN98 code

When you say ...

bernie said...
-- It has to be there because this code does the same thing. 
include std/memory.e 
sequence x 
x = sprintf(" %d ",{3217040639}) 
printf(1,x,{}) 
if getc(0) then end if 

Do you mean that what you see when executing this using Win98 binaries is "80000000"?

If so, what do you see when running the following ...

printf(" %d ",{3217040639}) 
if getc(0) then end if 
new topic     » goto parent     » topic index » view message » categorize

17. Re: ver 4.0 found the BUG in WIN98 code FOUND PROBLEM

I think we are talking about the same compiler here. Watcom C, and once it is compiled it will use the same registers and sizes. I don't think it is a compilation issue. Are you compiling these binaries on a Windows 98 machine? Have you tried the ones I am distributing? I think you should be able to reproduce the bug with either binary. If not, I am wrong.

Shawn

new topic     » goto parent     » topic index » view message » categorize

18. Re: ver 4.0 found the BUG in WIN98 code

DerekParnell said...

When you say ...

bernie said...
-- It has to be there because this code does the same thing. 
include std/memory.e 
sequence x 
x = sprintf(" %d ",{3217040639}) 
printf(1,x,{}) 
if getc(0) then end if 

Do you mean that what you see when executing this using Win98 binaries is "80000000"?

If so, what do you see when running the following ...

printf(" %d ",{3217040639}) 
if getc(0) then end if 

derek:

I get -2147483648 which lower limit of a signed long integer

new topic     » goto parent     » topic index » view message » categorize

19. Re: ver 4.0 found the BUG in WIN98 code FOUND PROBLEM

SDPringle said...

I think we are talking about the same compiler here. Watcom C, and once it is compiled it will use the same registers and sizes. I don't think it is a compilation issue. Are you compiling these binaries on a Windows 98 machine? Have you tried the ones I am distributing? I think you should be able to reproduce the bug with either binary. If not, I am wrong.

Shawn

I'am compiling on a WIN2000 machine using MANAGED_MEM option.
I'am running binary on a WIN98 machine.

new topic     » goto parent     » topic index » view message » categorize

20. Re: ver 4.0 found the BUG in WIN98 code

bernie said...
printf(" %d ",{3217040639}) 
if getc(0) then end if 

I get -2147483648 which lower limit of a signed long integer

What about:

   printf(" %d ",3217040639) 

The size of integers will be the same on all platforms on which euphoria currently runs. But euphoria will never store 0x80000000 as a euphoria integer. Any value that high will be stored as a double. And that's also the mask that the backend uses to denote a sequence. I'm not convinced yet that the problem is in the printf code.

BTW, were you running exwc or exw? Because printf/puts statements in the backend will be lost when not in console mode, because the compiled statements only output properly if you're running the console version of euphoria. I think it's because the compiled code doesn't know about the console that exw creates.

Matt

new topic     » goto parent     » topic index » view message » categorize

21. Re: ver 4.0 found the BUG in WIN98 code

Bloody hell Bernie! Are trying to make helping you difficult!?

Let's see if I can get a straight and complete answer this time...

You are getting -2147483648 when you use "sprintf".

You are also getting -2147483648 when you use "printf".

In other words, the program below ...

puts(1, sprintf("%d", 3217040639)) 
puts(1, " : from sprintf\n") 
printf(1, "%d : from printf\n", 3217040639) 

Shows the following on your screen...

-2147483648 : from sprintf 
-2147483648 : from printf 

Can you run the following two programs for me ...

-- Program 1 
atom a 
a = 3217040635 
for i = 1 to 10 do 
   puts(1, sprintf("%d: %d", {i, a})) 
   puts(1, "\n") 
   a += 1 
end for 
-- Program 2 
atom a 
a = -2147483645 
for i = 1 to 10 do 
   puts(1, sprintf("%d: %d", {i, a})) 
   puts(1, "\n") 
   a += 1 
end for 

And show us the results you are getting.

By the way, 0x80000000 when stored in a C long integer represents a sequence that has not been allocated any memory in Euphoria. It does NOT represent the lowest Euphoria integer value.

The value 0x800000000 when stored in Euphoria is actually stored as a C double and not a C int.

new topic     » goto parent     » topic index » view message » categorize

22. Re: ver 4.0 found the BUG in WIN98 code

DerekParnell said...

Bloody hell Bernie! Are trying to make helping you difficult!?

Let's see if I can get a straight and complete answer this time...

You are getting -2147483648 when you use "sprintf".

You are also getting -2147483648 when you use "printf".

In other words, the program below ...

puts(1, sprintf("%d", 3217040639)) 
puts(1, " : from sprintf\n") 
printf(1, "%d : from printf\n", 3217040639) 

Shows the following on your screen...

-2147483648 : from sprintf 
-2147483648 : from printf 

Can you run the following two programs for me ...

-- Program 1 
atom a 
a = 3217040635 
for i = 1 to 10 do 
   puts(1, sprintf("%d: %d", {i, a})) 
   puts(1, "\n") 
   a += 1 
end for 
-- Program 2 
atom a 
a = -2147483645 
for i = 1 to 10 do 
   puts(1, sprintf("%d: %d", {i, a})) 
   puts(1, "\n") 
   a += 1 
end for 

And show us the results you are getting.

By the way, 0x80000000 when stored in a C long integer represents a sequence that has not been allocated any memory in Euphoria. It does NOT represent the lowest Euphoria integer value.

The value 0x800000000 when stored in Euphoria is actually stored as a C double and not a C int.

 
You are getting -2147483648 when you use "sprintf". 
YES. 
 
You are also getting -2147483648 when you use "printf". 
YES. 
 
-- ============================================================================= 
This is exact screen printed out using EXW on WIN98 
 
 
Program 1 output 
1: -2147483648 
2: -2147483648 
3: -2147483648 
4: -2147483648 
5: -2147483648 
6: -2147483648 
7: -2147483648 
8: -2147483648 
9: -2147483648 
10: -2147483648 
 
Program 2 output 
1: -2147483645 
2: -2147483644 
3: -2147483643 
4: -2147483642 
5: -2147483641 
6: -2147483640 
7: -2147483639 
8: -2147483638 
9: -2147483637 
10: -2147483636 
 
This is exact screen printed out using EXWC on WIN98 
 
Program 1 output 
1: -2147483648 
2: -2147483648 
3: -2147483648 
4: -2147483648 
5: -2147483648 
6: -2147483648 
7: -2147483648 
8: -2147483648 
9: -2147483648 
10: -2147483648 
 
Program 2 output 
1: -2147483645 
2: -2147483644 
3: -2147483643 
4: -2147483642 
5: -2147483641 
6: -2147483640 
7: -2147483639 
8: -2147483638 
9: -2147483637 
10: -2147483636 
 
This is exact screen printed out using EX on WIN98 
 
Program 1 output 
1: -2147483648 
2: -2147483648 
3: -2147483648 
4: -2147483648 
5: -2147483648 
6: -2147483648 
7: -2147483648 
8: -2147483648 
9: -2147483648 
10: -2147483648 
 
Program 2 output 
1: -2147483645 
2: -2147483644 
3: -2147483643 
4: -2147483642 
5: -2147483641 
6: -2147483640 
7: -2147483639 
8: -2147483638 
9: -2147483637 
10: -2147483636 
 
-- ============================================================================= 
new topic     » goto parent     » topic index » view message » categorize

23. Re: ver 4.0 found the BUG in WIN98 code FOUND PROBLEM

SDPringle said...

I don't think it is a compilation issue.

I don't see the problem here on win98SE with many updated programs, IE6, directX 8 and then 9, SP3b2 and many others. any of which could have replaced a dll that is the cause for the bug. using exwc compiled locally w/watcom.

a few unittests could be added and something in sanity.ex to warn someone that erronious results can happen unless they patch their system. patch with what as yet to be determined.

bernie, which version of 98 is it?
rightclick my computer->properties.

anything else installed or is it a plain vanilla win98?

new topic     » goto parent     » topic index » view message » categorize

24. Re: ver 4.0 found the BUG in WIN98 code

I just built the system using managed-mem and ran the test programs I suggested.

It works correctly. That is

puts(1, sprintf("%d", 3217040639))  
puts(1, " : from sprintf\n")  
printf(1, "%d : from printf\n", 3217040639)  

shows ...

3217040639 : from sprintf 
3217040639 : from printf 
This was run on a WinXP system. I don't have Win98 and will never have it again (TTL), so I can't see how I can help with this one any more. At least we can be sure it is no 'Managed-Mem' itself causing this.

new topic     » goto parent     » topic index » view message » categorize

25. Re: ver 4.0 found the BUG in WIN98 code

This strange bug indeed is one that only shows up under certain situations should be squashed. Instead of looking at the printf code I would like to direct your attention to define_c_var code, that is, the underlying C code. It seems to me that somewhere the data is being corrupted inside EUPHORIA. The particular value returned by define_c_var, should vary between windows versions and patch levels. If we just patch the OS and shutup, we will leave a bug that could creep up again later.

Shawn Pringle

new topic     » goto parent     » topic index » view message » categorize

26. Re: ver 4.0 found the BUG in WIN98 code

SDPringle said...

This strange bug indeed is one that only shows up under certain situations should be squashed. Instead of looking at the printf code I would like to direct your attention to define_c_var code, that is, the underlying C code. It seems to me that somewhere the data is being corrupted inside EUPHORIA. The particular value returned by define_c_var, should vary between windows versions and patch levels. If we just patch the OS and shutup, we will leave a bug that could creep up again later.

I don't think it's define_c_var, because when he uses the '?' operator, it prints correctly. That's why I asked for Bernie to print in different ways. I haven't seen the results yet, but I suspect that it may be the RIGHT_BRACE operator that's causing the issues.

Either way, it's hard to debug, since no one else has been able to reproduce. Bernie, maybe you could step through it with the debugger, and let us know when the value gets corrupted.

Matt

new topic     » goto parent     » topic index » view message » categorize

27. Re: ver 4.0 found the BUG in WIN98 code FOUND PROBLEM

ne1uno said...

I don't see the problem here on win98SE with many updated programs, IE6, directX 8 and then 9, SP3b2 and many others. any of which could have replaced a dll that is the cause for the bug. using exwc compiled locally w/watcom.

a few unittests could be added and something in sanity.ex to warn someone that erronious results can happen unless they patch their system. patch with what as yet to be determined.

bernie, which version of 98 is it?
rightclick my computer->properties.

anything else installed or is it a plain vanilla win98?

I'am running WIN98 Second Edition. version 4.10.2222A
I also just ran the softpedia unofficial upgrade and it made no difference.

new topic     » goto parent     » topic index » view message » categorize

28. Re: ver 4.0 found the BUG in WIN98 code

mattlewis said...
SDPringle said...

This strange bug indeed is one that only shows up under certain situations should be squashed. Instead of looking at the printf code I would like to direct your attention to define_c_var code, that is, the underlying C code. It seems to me that somewhere the data is being corrupted inside EUPHORIA. The particular value returned by define_c_var, should vary between windows versions and patch levels. If we just patch the OS and shutup, we will leave a bug that could creep up again later.

I don't think it's define_c_var, because when he uses the '?' operator, it prints correctly. That's why I asked for Bernie to print in different ways. I haven't seen the results yet, but I suspect that it may be the RIGHT_BRACE operator that's causing the issues.

Either way, it's hard to debug, since no one else has been able to reproduce. Bernie, maybe you could step through it with the debugger, and let us know when the value gets corrupted.

Matt

Matt:
How do I use the debugger to step through the code ?

new topic     » goto parent     » topic index » view message » categorize

29. Re: ver 4.0 found the BUG in WIN98 code

bernie said...

Matt:
How do I use the debugger to step through the code ?

The first step is to build a debug version of euphoria. Clean the build, and then pass EDEBUG=1 to the wmake command line, in addition to the other stuff. When you installed OpenWatcom, it should have installed its debugger. Look in the start menu, launch it, and run the interpreter, set breakpoints, etc. There should also be a help file for the debugger and all the other stuff that comes with OW.

The debugger is console/text based, but is sort of graphical, like a curses app for windows.

Matt

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu