Skip to content

Commit

Permalink
Merge pull request #90 from sz3/bugfix-santitize-future
Browse files Browse the repository at this point in the history
Fix some longstanding (no)-fsanitize sloppiness
  • Loading branch information
sz3 authored Feb 8, 2024
2 parents e77b598 + 258991b commit 368c2c4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/lib/bit_file/bitbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ class bitbuffer

bool write(unsigned data, unsigned index, int length)
{
resize(index+length-1);
resize(index+length);

int currentByte = index/8;
int currentBit = index%8;

int nextWrite = std::min(length, 8-currentBit); // write this many bits
while (length > 0)
while (length > 0 and nextWrite > 0)
{
char bits = data >> (length - nextWrite);
unsigned char bits = data >> (length - nextWrite);
bits = bits << (8 - nextWrite - currentBit);
_buffer[currentByte] |= bits;

Expand All @@ -92,7 +92,7 @@ class bitbuffer
int nextRead = std::min(length, 8-currentBit); // read this many bits
while (length > 0)
{
unsigned char bits = _buffer[currentByte] << currentBit;
unsigned char bits = static_cast<unsigned char>(_buffer[currentByte]) << currentBit;
bits = bits >> (8-nextRead);
res |= bits << (length - nextRead);

Expand Down
2 changes: 1 addition & 1 deletion src/lib/cimb_translator/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ cv::Mat load_img(string path)
vector<unsigned char> data(bytes.data(), bytes.data() + bytes.size());

int width, height, channels;
std::unique_ptr<uint8_t[]> imgdata(stbi_load_from_memory(data.data(), static_cast<int>(data.size()), &width, &height, &channels, STBI_rgb_alpha));
std::unique_ptr<uint8_t[], void (*)(void*)> imgdata(stbi_load_from_memory(data.data(), static_cast<int>(data.size()), &width, &height, &channels, STBI_rgb_alpha), ::free);
if (!imgdata)
return cv::Mat();

Expand Down
2 changes: 1 addition & 1 deletion src/lib/cimb_translator/test/CimbDecoderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ TEST_CASE( "CimbDecoderTest/testAllColorDecodes", "[unit]" )
DYNAMIC_SECTION( "testColor " << c << ":" << i )
{
cv::Mat tile = cimbar::getTile(4, i, true, 4, c);
cv::Mat tenxten(10, 10, tile.type());
cv::Mat tenxten(10, 10, tile.type(), {0,0,0});
tile.copyTo(tenxten(cv::Rect(cv::Point(1, 1), tile.size())));

unsigned color = cd.decode_color(Cell(tenxten));
Expand Down

0 comments on commit 368c2c4

Please sign in to comment.