
I think I've come across a bug in the (==) function of PackedString, but it's hard to reproduce. I'm attaching a set of files that hopefully will reproduce the problem. My assumption is that if two packed strings are unequal, then when their unpacked versions must also be equal. This is, of course, assuming one starts with the packed versions, since packing of strings may be lossy... Anyhow, the guts of the problem is in the following (where c1 and c2 are packed strings): if c1 == c2 then return True else do putStr $ "First version:\n" putStr $ unpackPS c1 ++ "\n" putStr $ "second version:\n" putStr $ unpackPS c2 ++ "\n" if unpackPS c1 == unpackPS c2 then putStr "But unpacked, they are the same!!!\n" else putStr "And unpacked they are different!\n" return False I think that it is a bug if the line "But unpacked, they are the same!!!" ever gets printed (which it does--but it's hard to reproduce). This bug is rather troubling to me, since one of the reasons I'm using packed strings is for the assumed efficiency of comparison, the other being of course storage space, which would be sufficient in itself to mandate packed strings. Anyhow, I'm attaching a test program with a test file (which needs to be named both test1 and test2) which is able to reproduce an error in the above. Sorry I haven't made it any simpler. -- David Roundy http://www.abridgegame.org

I think I've come across a bug in the (==) function of PackedString, but it's hard to reproduce. I'm attaching a set of files that hopefully will reproduce the problem. My assumption is that if two packed strings are unequal, then when their unpacked versions must also be equal. This is, of course, assuming one starts with the packed versions, since packing of strings may be lossy...
This does appear to be a bug in the PackedString library. It appears that hGetPS doesn't zero-terminate the string, but the comparison code expects the strings to be zero-terminated. I'm not sure who's at fault here. The right fix is to use Data.PackedString instead of PackedString (no package lang required). Data.PackedString is a complete re-implementation and doesn't suffer from the bug you reported (that's not to say it doesn't have different bugs though!). Cheers, Simon

On Mon, Apr 28, 2003 at 11:26:40AM +0100, Simon Marlow wrote:
The right fix is to use Data.PackedString instead of PackedString (no package lang required). Data.PackedString is a complete re-implementation and doesn't suffer from the bug you reported (that's not to say it doesn't have different bugs though!).
Ah, that's good news! I had no idea they were different, and actually was sometimes importing one and sometimes the other! From now on I'll stick with Data.PackedString (which should also increase the usefulness of my bug reports, as they'll always be against the same version). -- David Roundy http://www.abridgegame.org
participants (2)
-
David Roundy
-
Simon Marlow