Fix PhanPluginDuplicateExpressionBinaryOp in DjVuImage (#9)
authorKunal Mehta <legoktm@member.fsf.org>
Sat, 6 Apr 2019 06:40:01 +0000 (23:40 -0700)
committerKunal Mehta <legoktm@member.fsf.org>
Sat, 6 Apr 2019 06:40:11 +0000 (23:40 -0700)
== has a higher precedence operator than &.

So the line `$chunkLength & 1 == 1` is interepreted as:
`$chunkLength & true`. Probably not what was intended, but it actually
works out because true is cast to 1, and the expression will either
result with 0 (falsey) or 1 (truthy), and we were looking for it to
equal 1 anyways. Incredible.

I assume that it was supposed to be `( $chunkLength & 1 ) == 1`, so I've
modified it to use that.

Change-Id: If03823b9286e0d8282519949bf46e2ba4cca0843

.phan/config.php
includes/media/DjVuImage.php

index 64197bf..c250bcd 100644 (file)
@@ -90,8 +90,6 @@ $cfg['suppress_issue_types'] = array_merge( $cfg['suppress_issue_types'], [
        // approximate error count: 127
        "PhanParamTooMany",
        // approximate error count: 2
-       "PhanPluginDuplicateExpressionBinaryOp",
-       // approximate error count: 2
        "PhanTraitParentReference",
        // approximate error count: 30
        "PhanTypeArraySuspicious",
index d059cd8..35cbc43 100644 (file)
@@ -108,7 +108,7 @@ class DjVuImage {
                                $this->dumpForm( $file, $chunkLength, $indent + 1 );
                        } else {
                                fseek( $file, $chunkLength, SEEK_CUR );
-                               if ( $chunkLength & 1 == 1 ) {
+                               if ( ( $chunkLength & 1 ) == 1 ) {
                                        // Padding byte between chunks
                                        fseek( $file, 1, SEEK_CUR );
                                }
@@ -166,7 +166,7 @@ class DjVuImage {
        private function skipChunk( $file, $chunkLength ) {
                fseek( $file, $chunkLength, SEEK_CUR );
 
-               if ( $chunkLength & 0x01 == 1 && !feof( $file ) ) {
+               if ( ( $chunkLength & 0x01 ) == 1 && !feof( $file ) ) {
                        // padding byte
                        fseek( $file, 1, SEEK_CUR );
                }