mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-18 02:55:12 +00:00
Fix goto in ncurses mode when compiled without BUILD_X11 (#680)
* Fix goto in ncurses mode when compiled without BUILD_X11 * Fix some issues raised by SonarCloud * Define delete_block_and_zero() function and use it to replace some malloc calls
This commit is contained in:
parent
f8ff46c2dc
commit
8d149471b5
39
src/conky.cc
39
src/conky.cc
@ -140,15 +140,15 @@
|
|||||||
#ifdef BUILD_BUILTIN_CONFIG
|
#ifdef BUILD_BUILTIN_CONFIG
|
||||||
#include "defconfig.h"
|
#include "defconfig.h"
|
||||||
|
|
||||||
|
#ifdef BUILD_OLD_CONFIG
|
||||||
|
#include "convertconf.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
const char builtin_config_magic[] = "==builtin==";
|
const char builtin_config_magic[] = "==builtin==";
|
||||||
} // namespace
|
} // namespace
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef BUILD_OLD_CONFIG
|
|
||||||
#include "convertconf.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef S_ISSOCK
|
#ifndef S_ISSOCK
|
||||||
#define S_ISSOCK(x) ((x & S_IFMT) == S_IFSOCK)
|
#define S_ISSOCK(x) ((x & S_IFMT) == S_IFSOCK)
|
||||||
#endif
|
#endif
|
||||||
@ -704,7 +704,7 @@ int spaced_print(char *buf, int size, const char *format, int width, ...) {
|
|||||||
char *tempbuf;
|
char *tempbuf;
|
||||||
|
|
||||||
if (size < 1) { return 0; }
|
if (size < 1) { return 0; }
|
||||||
tempbuf = static_cast<char *>(malloc(size * sizeof(char)));
|
tempbuf = new char[size];
|
||||||
|
|
||||||
// Passes the varargs along to vsnprintf
|
// Passes the varargs along to vsnprintf
|
||||||
va_start(argp, width);
|
va_start(argp, width);
|
||||||
@ -722,7 +722,7 @@ int spaced_print(char *buf, int size, const char *format, int width, ...) {
|
|||||||
len = snprintf(buf, size, "%-*s", width, tempbuf);
|
len = snprintf(buf, size, "%-*s", width, tempbuf);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
free(tempbuf);
|
delete [] tempbuf;
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -806,9 +806,9 @@ long get_current_text_color() { return current_text_color; }
|
|||||||
|
|
||||||
static void extract_variable_text(const char *p) {
|
static void extract_variable_text(const char *p) {
|
||||||
free_text_objects(&global_root_object);
|
free_text_objects(&global_root_object);
|
||||||
free_and_zero(tmpstring1);
|
delete_block_and_zero(tmpstring1);
|
||||||
free_and_zero(tmpstring2);
|
delete_block_and_zero(tmpstring2);
|
||||||
free_and_zero(text_buffer);
|
delete_block_and_zero(text_buffer);
|
||||||
|
|
||||||
extract_variable_text_internal(&global_root_object, p);
|
extract_variable_text_internal(&global_root_object, p);
|
||||||
}
|
}
|
||||||
@ -846,7 +846,7 @@ void generate_text_internal(char *p, int p_max_size, struct text_object root) {
|
|||||||
#ifdef BUILD_ICONV
|
#ifdef BUILD_ICONV
|
||||||
char *buff_in;
|
char *buff_in;
|
||||||
|
|
||||||
buff_in = (char *)malloc(p_max_size);
|
buff_in = new char[p_max_size];
|
||||||
memset(buff_in, 0, p_max_size);
|
memset(buff_in, 0, p_max_size);
|
||||||
#endif /* BUILD_ICONV */
|
#endif /* BUILD_ICONV */
|
||||||
|
|
||||||
@ -888,7 +888,7 @@ void generate_text_internal(char *p, int p_max_size, struct text_object root) {
|
|||||||
load_fonts(utf8_mode.get(*state));
|
load_fonts(utf8_mode.get(*state));
|
||||||
#endif /* BUILD_X11 */
|
#endif /* BUILD_X11 */
|
||||||
#ifdef BUILD_ICONV
|
#ifdef BUILD_ICONV
|
||||||
free(buff_in);
|
delete [] buff_in;
|
||||||
#endif /* BUILD_ICONV */
|
#endif /* BUILD_ICONV */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1648,9 +1648,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
|
|||||||
char *tmp_str;
|
char *tmp_str;
|
||||||
cur_x += font_ascent() / 2;
|
cur_x += font_ascent() / 2;
|
||||||
cur_y += font_h / 2;
|
cur_y += font_h / 2;
|
||||||
const int tmp_str_len = 64;
|
asprintf(&tmp_str, "%.1f", current->scale);
|
||||||
tmp_str = static_cast<char *>(calloc(tmp_str_len, sizeof(char)));
|
|
||||||
sprintf(tmp_str, "%.1f", current->scale);
|
|
||||||
draw_string(tmp_str);
|
draw_string(tmp_str);
|
||||||
free(tmp_str);
|
free(tmp_str);
|
||||||
cur_x = tmp_x;
|
cur_x = tmp_x;
|
||||||
@ -1749,6 +1747,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
|
|||||||
if (draw_mode == BG) { cur_x++; }
|
if (draw_mode == BG) { cur_x++; }
|
||||||
#endif /* BUILD_X11 */
|
#endif /* BUILD_X11 */
|
||||||
#ifdef BUILD_NCURSES
|
#ifdef BUILD_NCURSES
|
||||||
|
cur_x = static_cast<int>(current->arg);
|
||||||
if (out_to_ncurses.get(*state)) {
|
if (out_to_ncurses.get(*state)) {
|
||||||
int x, y;
|
int x, y;
|
||||||
getyx(ncurses_window, y, x);
|
getyx(ncurses_window, y, x);
|
||||||
@ -2575,9 +2574,9 @@ void clean_up_without_threads(void *memtofree1, void *memtofree2) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
free_text_objects(&global_root_object);
|
free_text_objects(&global_root_object);
|
||||||
free_and_zero(tmpstring1);
|
delete_block_and_zero(tmpstring1);
|
||||||
free_and_zero(tmpstring2);
|
delete_block_and_zero(tmpstring2);
|
||||||
free_and_zero(text_buffer);
|
delete_block_and_zero(text_buffer);
|
||||||
free_and_zero(global_text);
|
free_and_zero(global_text);
|
||||||
|
|
||||||
#ifdef BUILD_PORT_MONITORS
|
#ifdef BUILD_PORT_MONITORS
|
||||||
@ -3032,11 +3031,11 @@ void initialisation(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
text_buffer = static_cast<char *>(malloc(max_user_text.get(*state)));
|
text_buffer = new char[max_user_text.get(*state)];
|
||||||
memset(text_buffer, 0, max_user_text.get(*state));
|
memset(text_buffer, 0, max_user_text.get(*state));
|
||||||
tmpstring1 = static_cast<char *>(malloc(text_buffer_size.get(*state)));
|
tmpstring1 = new char [text_buffer_size.get(*state)];
|
||||||
memset(tmpstring1, 0, text_buffer_size.get(*state));
|
memset(tmpstring1, 0, text_buffer_size.get(*state));
|
||||||
tmpstring2 = static_cast<char *>(malloc(text_buffer_size.get(*state)));
|
tmpstring2 = new char [text_buffer_size.get(*state)];
|
||||||
memset(tmpstring2, 0, text_buffer_size.get(*state));
|
memset(tmpstring2, 0, text_buffer_size.get(*state));
|
||||||
|
|
||||||
#ifdef BUILD_X11
|
#ifdef BUILD_X11
|
||||||
|
@ -358,6 +358,14 @@ void free_and_zero(T *&ptr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void delete_block_and_zero(T *&ptr) {
|
||||||
|
if (ptr) {
|
||||||
|
delete [] ptr;
|
||||||
|
ptr = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extern std::unique_ptr<lua::state> state;
|
extern std::unique_ptr<lua::state> state;
|
||||||
|
|
||||||
extern int argc_copy;
|
extern int argc_copy;
|
||||||
|
Loading…
Reference in New Issue
Block a user