mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Remove VLA & calm Valgrind
`MB_CUR_MAX` looks like a macro, but it's a function call and therefore creates a VLA. We don't want that. Also this array being uninitialized created the following Valgrind error ``` ==503529== Conditional jump or move depends on uninitialised value(s) ==503529== at 0x619F15E: waddnstr (lib_addstr.c:67) ==503529== by 0x1929B7: _inp_write (inputwin.c:353) ==503529== by 0x1937D5: _inp_redisplay (inputwin.c:619) ==503529== by 0x61511B1: rl_forced_update_display (display.c:2693) ==503529== by 0x193F9D: _inp_rl_send_to_editor (inputwin.c:957) ==503529== by 0x614642F: _rl_dispatch_subseq (readline.c:916) ==503529== by 0x6146C85: _rl_dispatch_callback (readline.c:823) ==503529== by 0x616739F: rl_callback_read_char (callback.c:241) ==503529== by 0x1923DB: inp_readline (inputwin.c:188) ==503529== by 0x149860: prof_run (profanity.c:117) ==503529== by 0x2283E8: main (main.c:186) ==503529== Uninitialised value was created by a stack allocation ==503529== at 0x1928B1: _inp_write (inputwin.c:334) ``` Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
This commit is contained in:
parent
12d76e4a21
commit
197b839944
@ -60,6 +60,9 @@ void auto_free_char(char** str);
|
|||||||
#define STR_MAYBE_NULL(p) (p)
|
#define STR_MAYBE_NULL(p) (p)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Our own define of MB_CUR_MAX but this time at compile time */
|
||||||
|
#define PROF_MB_CUR_MAX 8
|
||||||
|
|
||||||
// assume malloc stores at most 8 bytes for size of allocated memory
|
// assume malloc stores at most 8 bytes for size of allocated memory
|
||||||
// and page size is at least 4KB
|
// and page size is at least 4KB
|
||||||
#define READ_BUF_SIZE 4088
|
#define READ_BUF_SIZE 4088
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#define _XOPEN_SOURCE_EXTENDED
|
#define _XOPEN_SOURCE_EXTENDED
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -140,6 +141,11 @@ static int _inp_rl_send_to_editor(int count, int key);
|
|||||||
void
|
void
|
||||||
create_input_window(void)
|
create_input_window(void)
|
||||||
{
|
{
|
||||||
|
/* MB_CUR_MAX is evaluated at runtime depending on the current
|
||||||
|
* locale, therefore we check that our own version is big enough
|
||||||
|
* and bail out if it isn't.
|
||||||
|
*/
|
||||||
|
assert(MB_CUR_MAX <= PROF_MB_CUR_MAX);
|
||||||
#ifdef NCURSES_REENTRANT
|
#ifdef NCURSES_REENTRANT
|
||||||
set_escdelay(25);
|
set_escdelay(25);
|
||||||
#else
|
#else
|
||||||
@ -331,7 +337,7 @@ _inp_write(char* line, int offset)
|
|||||||
|
|
||||||
for (size_t i = 0; line[i] != '\0'; i++) {
|
for (size_t i = 0; line[i] != '\0'; i++) {
|
||||||
char* c = &line[i];
|
char* c = &line[i];
|
||||||
char retc[MB_CUR_MAX];
|
char retc[PROF_MB_CUR_MAX] = { 0 };
|
||||||
|
|
||||||
size_t ch_len = mbrlen(c, MB_CUR_MAX, NULL);
|
size_t ch_len = mbrlen(c, MB_CUR_MAX, NULL);
|
||||||
if ((ch_len == (size_t)-2) || (ch_len == (size_t)-1)) {
|
if ((ch_len == (size_t)-2) || (ch_len == (size_t)-1)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user