Compiler Warning (level 3) CS0675 in DefalteManager.cs #55

Closed
opened 2026-01-29 22:05:53 +00:00 by claunia · 4 comments
Owner

Originally created by @haykpetros on GitHub (Aug 3, 2015).

When building SharpCompress project with Warning level above 2 (usually 4 is default) it will fail on lines 683 and 695 of DeflateManager.cs:

unchecked
            {
                if (bi_valid > (int) Buf_size - len)
                {
                    //int val = value;
                    //      bi_buf |= (val << bi_valid);

                    bi_buf |= (short) ((value << bi_valid) & 0xffff); <-- THIS IS WHERE IT FAILS
                    //put_short(bi_buf);
                    pending[pendingCount++] = (byte) bi_buf;
                    pending[pendingCount++] = (byte) (bi_buf >> 8);


                    bi_buf = (short) ((uint) value >> (Buf_size - bi_valid));
                    bi_valid += len - Buf_size;
                }
                else
                {
                    //      bi_buf |= (value) << bi_valid;
                    bi_buf |= (short) ((value << bi_valid) & 0xffff); <-- THIS IS WHERE IT FAILS
                    bi_valid += len;
                }
            }

I believe following line:

bi_buf |= (short) ((value << bi_valid) & 0xffff);

can be replaced using following code instead:

bi_buf = (short)(bi_buf | (short)((value << bi_valid) & 0xffff));
Originally created by @haykpetros on GitHub (Aug 3, 2015). When building SharpCompress project with Warning level above 2 (usually 4 is default) it will fail on lines 683 and 695 of DeflateManager.cs: ``` cs unchecked { if (bi_valid > (int) Buf_size - len) { //int val = value; // bi_buf |= (val << bi_valid); bi_buf |= (short) ((value << bi_valid) & 0xffff); <-- THIS IS WHERE IT FAILS //put_short(bi_buf); pending[pendingCount++] = (byte) bi_buf; pending[pendingCount++] = (byte) (bi_buf >> 8); bi_buf = (short) ((uint) value >> (Buf_size - bi_valid)); bi_valid += len - Buf_size; } else { // bi_buf |= (value) << bi_valid; bi_buf |= (short) ((value << bi_valid) & 0xffff); <-- THIS IS WHERE IT FAILS bi_valid += len; } } ``` I believe following line: ``` cs bi_buf |= (short) ((value << bi_valid) & 0xffff); ``` can be replaced using following code instead: ``` cs bi_buf = (short)(bi_buf | (short)((value << bi_valid) & 0xffff)); ```
Author
Owner

@adamhathcock commented on GitHub (Aug 3, 2015):

Thanks for this, could you make this a Pull Request by chance?

@adamhathcock commented on GitHub (Aug 3, 2015): Thanks for this, could you make this a Pull Request by chance?
Author
Owner

@haykpetros commented on GitHub (Aug 4, 2015):

It seems that this might be a bug in Visual Studio 2015, so we are going to wait until it is verified.

@haykpetros commented on GitHub (Aug 4, 2015): It seems that this might be a bug in Visual Studio 2015, so we are going to wait until it is verified.
Author
Owner

@Gachl commented on GitHub (Sep 15, 2015):

Considering that there's a wdc in MSDN about this I doubt this is a bug.

@Gachl commented on GitHub (Sep 15, 2015): Considering that there's a [wdc in MSDN about this](https://msdn.microsoft.com/en-us/library/wdc6717a.aspx) I doubt this is a bug.
Author
Owner

@benshoof commented on GitHub (Dec 15, 2015):

It's never a bug in the compiler... except this time. Even worse, a commit has been made to SharpCompress that tried to fix this but instead broke the build on VS2013 with a legitimate case of the warning it tried to prevent.

The deflate code is from DotNetZip from 2009 and has been working without any compiler saying peep until VS2015 showed up and threw CS0675. This change in compiler behavior is a bug: https://github.com/dotnet/roslyn/issues/4027

About a month ago, pull request https://github.com/adamhathcock/sharpcompress/pull/101 containing 18bd810228 changed the deflate code in what looks like an attempt to satisfy VS2015. Unfortunately it creates a real case of CS0675 that VS2013 does catch so right now the build is broken on VS2013.

I've created pull request https://github.com/adamhathcock/sharpcompress/pull/104 that reverts 18bd810228 and disables CS0675 warnings on Defalte.send_bits().

@benshoof commented on GitHub (Dec 15, 2015): It's never a bug in the compiler... except this time. Even worse, a commit has been made to SharpCompress that tried to fix this but instead broke the build on VS2013 with a legitimate case of the warning it tried to prevent. The deflate code is from DotNetZip from 2009 and has been working without any compiler saying peep until VS2015 showed up and threw CS0675. This change in compiler behavior is a bug: https://github.com/dotnet/roslyn/issues/4027 About a month ago, pull request https://github.com/adamhathcock/sharpcompress/pull/101 containing 18bd8102281c04c7eb09ecfdd984d7382b629f2c changed the deflate code in what looks like an attempt to satisfy VS2015. Unfortunately it creates a real case of CS0675 that VS2013 does catch so right now the build is broken on VS2013. I've created pull request https://github.com/adamhathcock/sharpcompress/pull/104 that reverts 18bd8102281c04c7eb09ecfdd984d7382b629f2c and disables CS0675 warnings on Defalte.send_bits().
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#55