Merge pull request #3552 from dougnazar/misc_fixes

Misc fixes
pull/3585/head
Isaac Connor 2022-08-25 18:33:25 -04:00 committed by GitHub
commit 36c69b3e2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 39 additions and 26 deletions

View File

@ -63,7 +63,7 @@ Camera::Camera(
{
linesize = width * colours;
pixels = width * height;
imagesize = height * linesize;
imagesize = static_cast<unsigned long long>(height) * linesize;
Debug(2, "New camera id: %d width: %d line size: %d height: %d colours: %d subpixelorder: %d capture: %d",
monitor->Id(), width, linesize, height, colours, subpixelorder, capture);

View File

@ -773,13 +773,7 @@ bool EventStream::sendFrame(Microseconds delta_us) {
}
Image *send_image = prepareImage(image);
if (temp_img_buffer_size < send_image->Size()) {
Debug(1, "Resizing image buffer from %zu to %u",
temp_img_buffer_size, send_image->Size());
delete[] temp_img_buffer;
temp_img_buffer = new uint8_t[send_image->Size()];
temp_img_buffer_size = send_image->Size();
}
reserveTempImgBuffer(send_image->Size());
int img_buffer_size = 0;
uint8_t *img_buffer = temp_img_buffer;

View File

@ -81,7 +81,11 @@ void zmFifoDbgOutput(
int len = va_arg(arg_ptr, int);
dbg_ptr += snprintf(dbg_ptr, str_size-(dbg_ptr-dbg_string), "%d:", len);
for ( int i = 0; i < len; i++ ) {
dbg_ptr += snprintf(dbg_ptr, str_size-(dbg_ptr-dbg_string), " %02x", data[i]);
const auto max_len = str_size - (dbg_ptr - dbg_string);
int rc = snprintf(dbg_ptr, max_len, " %02x", data[i]);
if (rc < 0 || rc > max_len)
break;
dbg_ptr += rc;
}
} else {
dbg_ptr += vsnprintf(dbg_ptr, str_size-(dbg_ptr-dbg_string), fstring, arg_ptr);

View File

@ -101,7 +101,7 @@ FontLoadError ZmFont::LoadFontFile(const std::string &loc) {
}
std::vector<uint64> bitmap;
bitmap.resize(bitmap_header.number_of_code_points * bitmap_header.char_height);
bitmap.resize(static_cast<std::size_t>(bitmap_header.number_of_code_points) * bitmap_header.char_height);
std::size_t bitmap_bytes = bitmap.size() * sizeof(uint64);
font_file.read(reinterpret_cast<char *>(bitmap.data()), static_cast<std::streamsize>(bitmap_bytes));

View File

@ -667,7 +667,7 @@ void Image::AssignDirect(
return;
}
size_t new_buffer_size = p_width * p_height * p_colours;
size_t new_buffer_size = static_cast<size_t>(p_width) * p_height * p_colours;
if ( buffer_size < new_buffer_size ) {
Error("Attempt to directly assign buffer from an undersized buffer of size: %zu, needed %dx%d*%d colours = %zu",
@ -2759,7 +2759,7 @@ void Image::Scale(const unsigned int new_width, const unsigned int new_height) {
if (width == new_width and height == new_height) return;
// Why larger than we need?
size_t scale_buffer_size = (new_width+1) * (new_height+1) * colours;
size_t scale_buffer_size = static_cast<size_t>(new_width+1) * (new_height+1) * colours;
uint8_t* scale_buffer = AllocBuffer(scale_buffer_size);
AVPixelFormat format = AVPixFormat();
@ -2789,7 +2789,7 @@ void Image::Scale(const unsigned int factor) {
unsigned int new_height = (height*factor)/ZM_SCALE_BASE;
// Why larger than we need?
size_t scale_buffer_size = (new_width+1) * (new_height+1) * colours;
size_t scale_buffer_size = static_cast<size_t>(new_width+1) * (new_height+1) * colours;
uint8_t* scale_buffer = AllocBuffer(scale_buffer_size);

View File

@ -481,7 +481,11 @@ void Logger::logPrint(bool hex, const char *filepath, int line, int level, const
int i;
logPtr += snprintf(logPtr, sizeof(logString)-(logPtr-logString), "%d:", len);
for ( i = 0; i < len; i++ ) {
logPtr += snprintf(logPtr, sizeof(logString)-(logPtr-logString), " %02x", data[i]);
const size_t max_len = sizeof(logString) - (logPtr - logString);
int rc = snprintf(logPtr, max_len, " %02x", data[i]);
if (rc < 0 || static_cast<size_t>(rc) > max_len)
break;
logPtr += rc;
}
} else {
logPtr += vsnprintf(logPtr, sizeof(logString)-(logPtr-logString), fstring, argPtr);

View File

@ -2748,24 +2748,29 @@ void Monitor::TimestampImage(Image *ts_image, SystemTimePoint ts_time) const {
while (*s_ptr && ((unsigned int)(d_ptr - label_text) < (unsigned int) sizeof(label_text))) {
if ( *s_ptr == config.timestamp_code_char[0] ) {
const auto max_len = sizeof(label_text) - (d_ptr - label_text);
bool found_macro = false;
int rc = 0;
switch ( *(s_ptr+1) ) {
case 'N' :
d_ptr += snprintf(d_ptr, sizeof(label_text)-(d_ptr-label_text), "%s", name.c_str());
rc = snprintf(d_ptr, max_len, "%s", name.c_str());
found_macro = true;
break;
case 'Q' :
d_ptr += snprintf(d_ptr, sizeof(label_text)-(d_ptr-label_text), "%s", trigger_data->trigger_showtext);
rc = snprintf(d_ptr, max_len, "%s", trigger_data->trigger_showtext);
found_macro = true;
break;
case 'f' :
typedef std::chrono::duration<int64, std::centi> Centiseconds;
Centiseconds centi_sec = std::chrono::duration_cast<Centiseconds>(
ts_time.time_since_epoch() - std::chrono::duration_cast<Seconds>(ts_time.time_since_epoch()));
d_ptr += snprintf(d_ptr, sizeof(label_text) - (d_ptr - label_text), "%02lld", static_cast<long long int>(centi_sec.count()));
rc = snprintf(d_ptr, max_len, "%02lld", static_cast<long long int>(centi_sec.count()));
found_macro = true;
break;
}
if (rc < 0 || static_cast<size_t>(rc) > max_len)
break;
d_ptr += rc;
if ( found_macro ) {
s_ptr += 2;
continue;

View File

@ -385,13 +385,7 @@ bool MonitorStream::sendFrame(Image *image, SystemTimePoint timestamp) {
/* double pts = */ vid_stream->EncodeFrame(send_image->Buffer(), send_image->Size(), config.mpeg_timed_frames, delta_time.count());
} else {
if (temp_img_buffer_size < send_image->Size()) {
Debug(1, "Resizing image buffer from %zu to %u",
temp_img_buffer_size, send_image->Size());
delete[] temp_img_buffer;
temp_img_buffer = new uint8_t[send_image->Size()];
temp_img_buffer_size = send_image->Size();
}
reserveTempImgBuffer(send_image->Size());
int img_buffer_size = 0;
unsigned char *img_buffer = temp_img_buffer;

View File

@ -334,6 +334,7 @@ void PacketQueue::clearPackets(const std::shared_ptr<ZMPacket> &add_packet) {
++it;
} // end while
Debug(1, "Resulting it pointing at latest packet? %d, next front points to begin? %d, Keyframe interval %d",
( *it == add_packet ),
( next_front == pktQueue.begin() ),

View File

@ -34,7 +34,7 @@ constexpr Milliseconds StreamBase::MAX_SLEEP;
StreamBase::~StreamBase() {
delete vid_stream;
delete temp_img_buffer;
delete[] temp_img_buffer;
closeComms();
}
@ -403,3 +403,13 @@ void StreamBase::closeComms() {
}
}
} // end void StreamBase::closeComms
void StreamBase::reserveTempImgBuffer(size_t size)
{
if (temp_img_buffer_size < size) {
Debug(1, "Resizing image buffer from %zu to %zu", temp_img_buffer_size, size);
delete[] temp_img_buffer;
temp_img_buffer = new uint8_t[size];
temp_img_buffer_size = size;
}
}

View File

@ -148,7 +148,7 @@ protected:
CmdMsg msg;
bool got_command = false; // commands like zoom should output a frame even if paused
unsigned char *temp_img_buffer; // Used when encoding or sending file data
uint8_t *temp_img_buffer; // Used when encoding or sending file data
size_t temp_img_buffer_size;
protected:
@ -158,6 +158,7 @@ protected:
Image *prepareImage(Image *image);
void checkCommandQueue();
virtual void processCommand(const CmdMsg *msg)=0;
void reserveTempImgBuffer(size_t size);
public:
StreamBase():