Some side tracking fixing undefined behaviour and memory vulnurabilities

This commit is contained in:
2023-12-03 13:20:30 +01:00
parent 28308dccad
commit 09a2e621d6
8 changed files with 69 additions and 42 deletions

View File

@@ -22,6 +22,7 @@
#include <cmath>
#include <cstdint>
#include <iostream>
#include <vector>
namespace ptprnt::graphics {
@@ -41,9 +42,9 @@ std::vector<uint8_t> Monochrome::get() {
unsigned int outIndex = 0;
for (unsigned int byteNum = 0; byteNum < mPixels.size(); byteNum += 8) {
for (unsigned int bitNo = 0; bitNo < 8; bitNo++) {
if (mPixels[byteNum + bitNo] > mThreshhold) {
for (unsigned int byteNo = 0; byteNo < mPixels.size(); byteNo += 8) {
for (unsigned int bitNo = 0; bitNo <= 7 && (byteNo + bitNo < mPixels.size()); bitNo++) {
if (mPixels[byteNo + bitNo] > mThreshhold) {
outPixels[outIndex] |= (1 << (7 - bitNo));
} else {
outPixels[outIndex] &= ~(1 << (7 - bitNo));