haskell / win32

Haskell support for the Win32 API
http://hackage.haskell.org/package/Win32
Other
97 stars 63 forks source link

Fix poke implementation for TIME_ZONE_INFORMATION #65

Closed RyanGlScott closed 7 years ago

RyanGlScott commented 7 years ago

It turns out the implementation of poke for TIME_ZONE_INFORMATION is incorrect for a number of reasons:

  1. Foremost, the order of arguments to copyArray is completely wrong. The first array is the destination and the second is the source, so we need to flip the order in which the arguments currently appear.
  2. We weren't copying enough bytes in the first place, as withCWStringLen gives you the length of the string, not the number of bytes. Luckily, this is easily fixed by multiplying len by sizeOf (undefined :: CWchar).
  3. We need to ensure that we null-terminate the CWstring with an actual CWchar, not a Word8. I've observed that doing the latter can sometimes yield garbage strings.

Fixes #64.

RyanGlScott commented 7 years ago

We should probably add a test for this, but I'm not familiar with how Win32 handles its tests. I don't see a test-suite stanza in Win32.cabal either...

Mistuke commented 7 years ago

Thanks @RyanGlScott LGTM.

Win32's tests are inline GHC tests. So you just have to write them like you would using the GHC testsuite.

I usually just add a remote to my github to libraries\Win32 to be able to run the tests.

Mistuke commented 7 years ago

Sweet, thanks @RyanGlScott I'll merge soon.