From: David Lawrence Ramsey Date: Thu, 22 Apr 2004 03:41:04 +0000 (+0000) Subject: make the verbatim and escape sequence input routines use size_t's to X-Git-Tag: v1.3.3~101 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=805547fed0ea64b83bd194de08a651cd98d6253f;p=nano.git make the verbatim and escape sequence input routines use size_t's to hold lengths, and use a properly cast nrealloc() instead of an uncast realloc() in the former git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1717 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index 3c21ac70..de84318a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -14,6 +14,10 @@ CVS code - - nano.c: do_delete() - Tweak for efficiency. (David Benbennick) + do_verbatim_kbinput() + - Use size_t's instead of ints for the get_verbatim_kbinput() + call and the loop that ungetch()es its returned int*, + respectively. (DLR) - proto.h: - Remove unused add_marked_sameline() prototype. (DLR) - rcfile.c: @@ -39,6 +43,14 @@ CVS code - - Refactor the output in the DEBUG #ifdef. It didn't work properly ever since this function was changed to use an int* instead of a char*. (DLR) + - Change kbinput_len from an int* to a size_t*, since it should + never be negative. (DLR) + - When reading characters from input, properly reallocate + verbatim_kbinput via (int*)nrealloc() instead of an uncast + realloc(). (DLR) + get_escape_seq_kbinput() + - Change escape_seq_len from an int to a size_t, since it should + never be negative. (DLR) edit_refresh() - Remove apparently unneeded leaveok() calls. (David Benbennick) - nano.texi: diff --git a/src/nano.c b/src/nano.c index 4a11b1b4..6ea3c359 100644 --- a/src/nano.c +++ b/src/nano.c @@ -998,8 +998,8 @@ void do_char(char ch) int do_verbatim_input(void) { int *verbatim_kbinput; /* Used to hold verbatim input. */ - int verbatim_len; /* Length of verbatim input. */ - int i; + size_t verbatim_len; /* Length of verbatim input. */ + size_t i; statusbar(_("Verbatim input")); verbatim_kbinput = get_verbatim_kbinput(edit, &verbatim_len, 1); diff --git a/src/proto.h b/src/proto.h index 11eec4ab..489ee7dc 100644 --- a/src/proto.h +++ b/src/proto.h @@ -452,12 +452,12 @@ int check_wildcard_match(const char *text, const char *pattern); /* Public functions in winio.c */ int get_kbinput(WINDOW *win, int *meta_key); -int *get_verbatim_kbinput(WINDOW *win, int *kbinput_len, int +int *get_verbatim_kbinput(WINDOW *win, size_t *kbinput_len, int allow_ascii); int get_ignored_kbinput(WINDOW *win); int get_accepted_kbinput(WINDOW *win, int kbinput, int *meta_key); int get_ascii_kbinput(WINDOW *win, int kbinput); -int get_escape_seq_kbinput(WINDOW *win, int *escape_seq, int +int get_escape_seq_kbinput(WINDOW *win, int *escape_seq, size_t escape_seq_len); int get_escape_seq_abcd(int kbinput); int get_mouseinput(int *mouse_x, int *mouse_y, int shortcut); diff --git a/src/winio.c b/src/winio.c index a4cfdf13..dd56cf4e 100644 --- a/src/winio.c +++ b/src/winio.c @@ -65,7 +65,7 @@ int get_kbinput(WINDOW *win, int *meta_key) /* Read in a string of input characters (e.g. an escape sequence) * verbatim, and return the length of the string in kbinput_len. Assume * nodelay(win) is FALSE. */ -int *get_verbatim_kbinput(WINDOW *win, int *kbinput_len, int +int *get_verbatim_kbinput(WINDOW *win, size_t *kbinput_len, int allow_ascii) { int kbinput, *verbatim_kbinput; @@ -101,7 +101,7 @@ int *get_verbatim_kbinput(WINDOW *win, int *kbinput_len, int #endif while ((kbinput = wgetch(win)) != ERR) { (*kbinput_len)++; - verbatim_kbinput = realloc(verbatim_kbinput, *kbinput_len * sizeof(int)); + verbatim_kbinput = (int *)nrealloc(verbatim_kbinput, *kbinput_len * sizeof(int)); verbatim_kbinput[*kbinput_len - 1] = kbinput; #ifdef DEBUG fprintf(stderr, "get_verbatim_kbinput(): kbinput = %d\n", kbinput); @@ -196,7 +196,8 @@ int get_accepted_kbinput(WINDOW *win, int kbinput, int *meta_key) * Hemel. */ case '[': { - int old_kbinput = kbinput, *escape_seq, escape_seq_len; + int old_kbinput = kbinput, *escape_seq; + size_t escape_seq_len; nodelay(win, TRUE); kbinput = wgetch(win); switch (kbinput) { @@ -371,7 +372,7 @@ int get_ascii_kbinput(WINDOW *win, int kbinput) * omitted. (Same as above.) * - The Hurd console has no escape sequences for F11, F12, F13, or * F14. */ -int get_escape_seq_kbinput(WINDOW *win, int *escape_seq, int +int get_escape_seq_kbinput(WINDOW *win, int *escape_seq, size_t escape_seq_len) { int kbinput = ERR;