From 16534ec64492b7c08e5837b9da83072452813f28 Mon Sep 17 00:00:00 2001 From: Konrad Borowski Date: Sun, 4 May 2014 15:46:15 +0200 Subject: [PATCH 1/6] Improve test_wchar2utf8(). Currently it contains strange code like using `do` loop in order to avoid `goto`s (they aren't evil, honestly), the pointless `if (mem)` conditional which doesn't even work (had semicolon for some reason). You may think this code had a bug where the code didn't check for the pointer to be null before calling `free`, but this is not the case, as according to C and C++ standard, `free` should allow `NULL` pointers, and ignore them. --- fish_tests.cpp | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/fish_tests.cpp b/fish_tests.cpp index eca030971..f82633c63 100644 --- a/fish_tests.cpp +++ b/fish_tests.cpp @@ -1021,28 +1021,23 @@ static void test_wchar2utf8(const wchar_t *src, size_t slen, const char *dst, si } } - do + size = wchar_to_utf8(src, slen, mem, dlen, flags); + if (res != size) { - size = wchar_to_utf8(src, slen, mem, dlen, flags); - if (res != size) - { - err(L"w2u: %s: FAILED (rv: %lu, must be %lu)", descr, size, res); - break; - } - - if (mem == NULL) - break; /* OK */ - - if (memcmp(mem, dst, size) != 0) - { - err(L"w2u: %s: BROKEN", descr); - break; - } - + err(L"w2u: %s: FAILED (rv: %lu, must be %lu)", descr, size, res); + goto finish; } - while (0); - if (mem != NULL); + if (mem == NULL) + goto finish; /* OK */ + + if (memcmp(mem, dst, size) != 0) + { + err(L"w2u: %s: BROKEN", descr); + goto finish; + } + + finish: free(mem); } From 13e1e7e1e94fb2102986e826765c7801f6cd8332 Mon Sep 17 00:00:00 2001 From: Konrad Borowski Date: Tue, 6 May 2014 12:07:16 +0200 Subject: [PATCH 2/6] Fix NULL dereference when function name is not specified It was possible to type `function ""; end`, and this caused fish to crash because of NULL pointer. --- builtin.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/builtin.cpp b/builtin.cpp index 741dbd4ad..fadd5a4a1 100644 --- a/builtin.cpp +++ b/builtin.cpp @@ -2002,6 +2002,7 @@ int define_function(parser_t &parser, const wcstring_list_t &c_args, const wcstr else if (! wcslen(argv[woptind])) { append_format(*out_err, _(L"%ls: No function name given\n"), argv[0]); + res=1; } else { From 91ebe12fc2d54f952d046716d85db13de00288e7 Mon Sep 17 00:00:00 2001 From: Konrad Borowski Date: Tue, 6 May 2014 12:18:09 +0200 Subject: [PATCH 3/6] Add test for empty function name. --- tests/test10.err | 4 ++++ tests/test10.in | 3 +++ tests/test10.out | 1 + tests/test10.status | 1 + 4 files changed, 9 insertions(+) create mode 100644 tests/test10.err create mode 100644 tests/test10.in create mode 100644 tests/test10.out create mode 100644 tests/test10.status diff --git a/tests/test10.err b/tests/test10.err new file mode 100644 index 000000000..abf6ca379 --- /dev/null +++ b/tests/test10.err @@ -0,0 +1,4 @@ +function: No function name given + +fish: function "" + ^ diff --git a/tests/test10.in b/tests/test10.in new file mode 100644 index 000000000..bcb5985a1 --- /dev/null +++ b/tests/test10.in @@ -0,0 +1,3 @@ +function "" +end +echo Hello, world! diff --git a/tests/test10.out b/tests/test10.out new file mode 100644 index 000000000..af5626b4a --- /dev/null +++ b/tests/test10.out @@ -0,0 +1 @@ +Hello, world! diff --git a/tests/test10.status b/tests/test10.status new file mode 100644 index 000000000..573541ac9 --- /dev/null +++ b/tests/test10.status @@ -0,0 +1 @@ +0 From 7f2c4cbf8a1c961b06c3801ce00a9233fb78d2d1 Mon Sep 17 00:00:00 2001 From: Konrad Borowski Date: Tue, 6 May 2014 12:31:44 +0200 Subject: [PATCH 4/6] Move the empty function test to tests. --- fish_tests.cpp | 3 +++ tests/test10.err | 4 ---- tests/test10.in | 3 --- tests/test10.out | 1 - tests/test10.status | 1 - 5 files changed, 3 insertions(+), 9 deletions(-) delete mode 100644 tests/test10.err delete mode 100644 tests/test10.in delete mode 100644 tests/test10.out delete mode 100644 tests/test10.status diff --git a/fish_tests.cpp b/fish_tests.cpp index f82633c63..c7b2222b4 100644 --- a/fish_tests.cpp +++ b/fish_tests.cpp @@ -687,6 +687,9 @@ static void test_parser() parser_t::principal_parser().eval(L"function recursive1 ; recursive2 ; end ; function recursive2 ; recursive1 ; end ; recursive1; ", io_chain_t(), TOP); #endif + say(L"Testing empty function name"); + parser_t::principal_parser().eval(L"function '' ; echo fail; exit 42 ; end ; ''", io_chain_t(), TOP); + say(L"Testing eval_args"); completion_list_t comps; parser_t::principal_parser().expand_argument_list(L"alpha 'beta gamma' delta", comps); diff --git a/tests/test10.err b/tests/test10.err deleted file mode 100644 index abf6ca379..000000000 --- a/tests/test10.err +++ /dev/null @@ -1,4 +0,0 @@ -function: No function name given - -fish: function "" - ^ diff --git a/tests/test10.in b/tests/test10.in deleted file mode 100644 index bcb5985a1..000000000 --- a/tests/test10.in +++ /dev/null @@ -1,3 +0,0 @@ -function "" -end -echo Hello, world! diff --git a/tests/test10.out b/tests/test10.out deleted file mode 100644 index af5626b4a..000000000 --- a/tests/test10.out +++ /dev/null @@ -1 +0,0 @@ -Hello, world! diff --git a/tests/test10.status b/tests/test10.status deleted file mode 100644 index 573541ac9..000000000 --- a/tests/test10.status +++ /dev/null @@ -1 +0,0 @@ -0 From fa68c2619fe844395287c33c9109f6decb322410 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Fri, 9 May 2014 14:37:23 -0700 Subject: [PATCH 5/6] Use parm_left_cursor and parm_right_cursor for bulk cursor motions. Fixes #1448 --- output.cpp | 24 +++++++++++++++++------- output.h | 29 ++--------------------------- screen.cpp | 20 +++++++++++++++++--- 3 files changed, 36 insertions(+), 37 deletions(-) diff --git a/output.cpp b/output.cpp index 7f90df4bd..149d9d99a 100644 --- a/output.cpp +++ b/output.cpp @@ -418,13 +418,6 @@ int writeb(tputs_arg_t b) return 0; } -int writembs_internal(char *str) -{ - CHECK(str, 1); - - return tputs(str,1,&writeb)==ERR?1:0; -} - int writech(wint_t ch) { mbstate_t state; @@ -725,3 +718,20 @@ const wchar_t *output_get_term() { return current_term.empty() ? L"" : current_term.c_str(); } + +void writembs_check(char *mbs, const char *mbs_name, const char *file, long line) +{ + if (mbs != NULL) + { + tputs(mbs, 1, &writeb); + } + else + { + debug( 0, _(L"Tried to use terminfo string %s on line %ld of %s, which is undefined in terminal of type \"%ls\". Please report this error to %s"), + mbs_name, + line, + file, + output_get_term(), + PACKAGE_BUGREPORT); + } +} diff --git a/output.h b/output.h index 2d05c3d05..400129421 100644 --- a/output.h +++ b/output.h @@ -78,33 +78,8 @@ void set_color(rgb_color_t c, rgb_color_t c2); /** Write specified multibyte string */ -#define writembs( mbs ) \ - { \ - char *tmp = mbs; \ - if( tmp ) \ - { \ - writembs_internal( tmp ); \ - } \ - else \ - { \ - debug( 0, \ - _(L"Tried to use terminfo string %s on line %d of %s, which is undefined in terminal of type \"%ls\". Please report this error to %s"), \ - #mbs, \ - __LINE__, \ - __FILE__, \ - output_get_term(), \ - PACKAGE_BUGREPORT); \ - } \ - } - - -/** - Write a char * narrow string to FD 1, needed for the terminfo - strings. This is usually just a wrapper aound tputs, using writeb - as the sending function. But a weird bug on PPC Linux means that on - this platform, write is instead used directly. -*/ -int writembs_internal(char *str); +void writembs_check(char *mbs, const char *mbs_name, const char *file, long line); +#define writembs(mbs) writembs_check((mbs), #mbs, __FILE__, __LINE__) /** Write a wide character using the output method specified using output_set_writer(). diff --git a/screen.cpp b/screen.cpp index 2fd7cc96d..96fe0f2a5 100644 --- a/screen.cpp +++ b/screen.cpp @@ -638,18 +638,32 @@ static void s_move(screen_t *s, data_buffer_t *b, int new_x, int new_y) x_steps = 0; } + char *multi_str = NULL; if (x_steps < 0) { str = cursor_left; + multi_str = parm_left_cursor; } else { str = cursor_right; + multi_str = parm_right_cursor; } - - for (i=0; i strlen(multi_str)); + if (use_multi) { - writembs(str); + char *multi_param = tparm(multi_str, abs(x_steps)); + writembs(multi_param); + } + else + { + for (i=0; i Date: Fri, 9 May 2014 23:09:29 +0200 Subject: [PATCH 6/6] Automatically add include paths for ncurses on Cygwin --- configure.ac | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/configure.ac b/configure.ac index 68b53c208..40693d6e7 100644 --- a/configure.ac +++ b/configure.ac @@ -213,6 +213,16 @@ if test `uname` != "Darwin"; then LDFLAGS_FISH="$LDFLAGS_FISH -rdynamic" fi +# +# On Cygwin, we need to add some flags for ncurses. +# +case `uname` in + CYGWIN*) + echo "adding flags for ncurses on Cygwin" + CXXFLAGS="$CXXFLAGS -I/usr/include -I/usr/include/ncursesw" + LDFLAGS_FISH="$LDFLAGS_FISH -L/usr/lib/ncursesw" + ;; +esac # # If we are compiling against glibc, set some flags to work around