digitalmars.D.learn - A bug due to negating object.sizeof
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (20/20) Jan 25 2012 There has been two threads abo...
There has been two threads about signed/unsigned recently on the main D forum, especially on the size_t and sizediff_t aliases. This is not directly related to those aliases but here is a fresh bug of mine. The following code attempts to point at the ID3v1 block from the end of an mp3 file: dosya.seek(-ID3v1Pakedi.sizeof, SEEK_END); Although there is a bug, it works on my 64-bit Linux environment. Fortunately, it failed on a Windows system when compiled with the 32-bit dmd 2.057. Since .sizeof is unsigned, negating it produces a very large unsigned value, which goes through to!int in std.stdio.File.seek. That conversion works fine on my 64-bit environment and the program works as expected, but it fails on that Windows system with the following exception: std.conv.ConvOverflowException std\conv.d(1302): Conversion positive overflow Yes, the code is buggy and my fix is the following (although not tested on Windows yet! :p): dosya.seek(-cast(long)ID3v1Pakedi.sizeof, SEEK_END); Just throwing it out there as a reminder... Ali
Jan 25 2012