majestic53 / libanvil

A C++ library for reading and writing Minecraft "Anvil" files
GNU General Public License v3.0
30 stars 12 forks source link

byte[] not correctly converted into int/long #8

Open siarsky opened 4 years ago

siarsky commented 4 years ago

The library is cutting bits due to rotating of bits on a type unsigned char instead of the T type. Patch in PS

PS:

diff --git a/include/byte_stream.h b/include/byte_stream.h
index 69afb1f..5f4219f 100644
--- a/include/byte_stream.h
+++ b/include/byte_stream.h
@@ -61,7 +61,7 @@ private:
            swap_endian(data);
        var = 0;
        for(unsigned int i = 0; i < width; ++i)
-           var |= (data.at(i) << (8 * ((width - 1) - i)));
+           var |= ((T)data.at(i) << (8 * ((width - 1) - i)));
        return SUCCESS;
    }