Daniel Berger
2009-Aug-16 20:14 UTC
[Win32utils-devel] win32-api, unsigned long vs long in api_call
Hi, I noticed this bug: Windows XP Pro Ruby 1.8.6-p383 built with VC++ 9 win32-api 1.4.3 C:\>irb irb(main):001:0> require ''win32/api'' => true irb(main):002:0> GetFileAttributes Win32::API.new(''GetFileAttributes'', ''S'', ''L'') => #<Win32::API:0x2db8880> irb(main):003:0> GetFileAttributes.call("C:/aaabbbcccxxx") # bogus file, should return -1 => 4294967295 I looked at win32-api.c, line 743, and I saw that, in the api_call function, we''ve declared the return_value variable an unsigned long. I changed it to a signed long as well as switching a ULONG2NUM call to LONG2NUM and that fixed it. I''m kinda shocked I didn''t see this until now. Is there any reason for me not to apply this change immediately? I''m trying to remember why I made it unsigned to begin with. Regards, Dan
Daniel Berger
2009-Aug-19 15:07 UTC
[Win32utils-devel] win32-api, unsigned long vs long in api_call
On Sun, Aug 16, 2009 at 2:14 PM, Daniel Berger<djberg96 at gmail.com> wrote:> Hi, > > I noticed this bug: > > Windows XP Pro > Ruby 1.8.6-p383 built with VC++ 9 > win32-api 1.4.3 > > C:\>irb > irb(main):001:0> require ''win32/api'' > => true > irb(main):002:0> GetFileAttributes > Win32::API.new(''GetFileAttributes'', ''S'', ''L'') > => #<Win32::API:0x2db8880> > irb(main):003:0> GetFileAttributes.call("C:/aaabbbcccxxx") # bogus > file, should return -1 > => 4294967295 > > I looked at win32-api.c, line 743, and I saw that, in the api_call > function, we''ve declared the return_value variable an unsigned long. I > changed it to a signed long as well as switching a ULONG2NUM call to > LONG2NUM and that fixed it. > > I''m kinda shocked I didn''t see this until now. Is there any reason for > me not to apply this change immediately? I''m trying to remember why I > made it unsigned to begin with.I''ve gone ahead and changed it for 1.4.4. If it turns out to be a critical mistake I''ll undo it. Regards, Dan