From 560b6f9dc2c510b9eeafdf714adb9f5700a9a034 Mon Sep 17 00:00:00 2001 From: Jacob Litewski Date: Fri, 19 Apr 2024 07:53:20 -0400 Subject: [PATCH] Marker V2 fixes --- client/src/proxgui.cpp | 8 ++++---- client/src/proxguiqt.cpp | 22 +++++++--------------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/client/src/proxgui.cpp b/client/src/proxgui.cpp index f4849a6a1..9d326f636 100644 --- a/client/src/proxgui.cpp +++ b/client/src/proxgui.cpp @@ -139,7 +139,7 @@ extern "C" void InitGraphics(int argc, char **argv, char *script_cmds_file, char void add_temporary_marker(uint32_t position, const char *label) { if(g_TempMarkerSize == 0) { //Initialize the marker array - g_TempMarkers = (marker_t*)malloc(sizeof(marker_t)); + g_TempMarkers = (marker_t*)calloc(1, sizeof(marker_t)); } else { //add more space to the marker array using realloc() marker_t *temp = (marker_t*)realloc(g_TempMarkers, ((g_TempMarkerSize + 1) * sizeof(marker_t))); @@ -155,12 +155,12 @@ void add_temporary_marker(uint32_t position, const char *label) { g_TempMarkers[g_TempMarkerSize].pos = position; - char *markerLabel = (char*)malloc(strlen(label)); + char *markerLabel = (char*)calloc(1, strlen(label) + 1); strcpy(markerLabel, label); - if(strlen(markerLabel) > 29) { + if(strlen(markerLabel) > 30) { PrintAndLogEx(WARNING, "Label for temporary marker too long! Trunicating..."); - markerLabel[29] = '\0'; + markerLabel[30] = '\0'; } strncpy(g_TempMarkers[g_TempMarkerSize].label, markerLabel, 30); diff --git a/client/src/proxguiqt.cpp b/client/src/proxguiqt.cpp index 21ea0dfa6..d40f98e03 100644 --- a/client/src/proxguiqt.cpp +++ b/client/src/proxguiqt.cpp @@ -783,8 +783,7 @@ void Plot::drawAnnotations(QRect annotationRect, QPainter *painter) { char graphText[] = "@%u..%u dt=%i %s zoom=%2.3f"; length = ((sizeof(graphText))+(sizeof(uint32_t)*3)+sizeof(scalestr)+sizeof(float_t)); - annotation = (char*)malloc(length); - memset(annotation, 0x00, length); + annotation = (char*)calloc(1, length); snprintf(annotation, length, graphText, g_GraphStart, @@ -805,8 +804,7 @@ void Plot::drawAnnotations(QRect annotationRect, QPainter *painter) { char gridText[] = "GridX=%lf GridY=%lf (%s) GridXoffset=%lf"; length = (sizeof(gridText) + (sizeof(double)*3) + sizeof(gridLocked)); - annotation = (char*)malloc(length); - memset(annotation, 0x00, length); + annotation = (char*)calloc(1, length); snprintf(annotation, length, gridText, g_DefaultGridX, @@ -832,11 +830,8 @@ void Plot::drawAnnotations(QRect annotationRect, QPainter *painter) { bool flag = false; size_t value; - annotation = (char*)malloc(length); - char *textA = (char*)malloc(length); - - memset(annotation, 0x00, length); - memset(textA, 0x00, length); + annotation = (char*)calloc(1, length); + char *textA = (char*)calloc(1, length); strcat(textA, markerText); strcat(textA, " (%s%u)"); @@ -867,8 +862,7 @@ void Plot::drawAnnotations(QRect annotationRect, QPainter *painter) { length = ((sizeof(markerText))+(sizeof(uint32_t)*2)+1); pos = g_MarkerB.pos; - annotation = (char*)malloc(length); - memset(annotation, 0x00, length); + annotation = (char*)calloc(1, length); snprintf(annotation, length, markerText, "B", @@ -885,8 +879,7 @@ void Plot::drawAnnotations(QRect annotationRect, QPainter *painter) { length = ((sizeof(markerText))+(sizeof(uint32_t)*2)+1); pos = g_MarkerC.pos; - annotation = (char*)malloc(length); - memset(annotation, 0x00, length); + annotation = (char*)calloc(1, length); snprintf(annotation, length, markerText, "C", @@ -903,8 +896,7 @@ void Plot::drawAnnotations(QRect annotationRect, QPainter *painter) { length = ((sizeof(markerText))+(sizeof(uint32_t)*2)+1); pos = g_MarkerD.pos; - annotation = (char*)malloc(length); - memset(annotation, 0x00, length); + annotation = (char*)calloc(1, length); snprintf(annotation, length, markerText, "D",