diff --git a/src/gui/curses/gui-curses-chat.c b/src/gui/curses/gui-curses-chat.c index b4fa4cc92..6ab731b83 100644 --- a/src/gui/curses/gui-curses-chat.c +++ b/src/gui/curses/gui-curses-chat.c @@ -1544,7 +1544,7 @@ gui_chat_display_line (struct t_gui_window *window, struct t_gui_line *line, /* if message ends with spaces, display them */ if ((word_length <= 0) && (word_length_with_spaces > 0) - && !ptr_data[word_end_offset + 1]) + && !ptr_data[word_end_offset]) { word_length = word_length_with_spaces; } @@ -1582,7 +1582,7 @@ gui_chat_display_line (struct t_gui_window *window, struct t_gui_line *line, /* display word */ gui_chat_display_word (window, line, ptr_data, - ptr_end_offset + 1, + ptr_end_offset, 0, num_lines, count, pre_lines_displayed, &lines_displayed, simulate, @@ -1594,7 +1594,7 @@ gui_chat_display_line (struct t_gui_window *window, struct t_gui_line *line, else { /* move pointer after end of word */ - ptr_data = ptr_end_offset + 1; + ptr_data = ptr_end_offset; if (*(ptr_data - 1) == '\0') ptr_data = NULL; diff --git a/src/gui/gui-chat.c b/src/gui/gui-chat.c index 59c1e339f..44f847d25 100644 --- a/src/gui/gui-chat.c +++ b/src/gui/gui-chat.c @@ -338,7 +338,7 @@ gui_chat_get_word_info (struct t_gui_window *window, { if (next_char[0] == '\n') { - *word_end_offset = next_char - start_data - 1; + *word_end_offset = next_char - start_data; if (*word_length < 0) *word_length = 0; return; @@ -348,7 +348,7 @@ gui_chat_get_word_info (struct t_gui_window *window, if (leading_spaces) *word_start_offset = next_char - start_data; leading_spaces = 0; - *word_end_offset = next_char2 - start_data - 1; + *word_end_offset = next_char2 - start_data; char_size_screen = utf8_char_size_screen (next_char); if (char_size_screen > 0) (*word_length_with_spaces) += char_size_screen; @@ -362,11 +362,11 @@ gui_chat_get_word_info (struct t_gui_window *window, if (leading_spaces) { (*word_length_with_spaces)++; - *word_end_offset = next_char2 - start_data - 1; + *word_end_offset = next_char2 - start_data; } else { - *word_end_offset = next_char - start_data - 1; + *word_end_offset = next_char - start_data; return; } } @@ -375,7 +375,7 @@ gui_chat_get_word_info (struct t_gui_window *window, } else { - *word_end_offset = data + strlen (data) - start_data - 1; + *word_end_offset = data + strlen (data) - start_data; return; } } diff --git a/tests/unit/gui/test-gui-chat.cpp b/tests/unit/gui/test-gui-chat.cpp index a9a46569c..354271c5a 100644 --- a/tests/unit/gui/test-gui-chat.cpp +++ b/tests/unit/gui/test-gui-chat.cpp @@ -339,31 +339,31 @@ TEST(GuiChat, GetWordInfo) WEE_GET_WORD_INFO (0, 0, 0, -1, NULL); WEE_GET_WORD_INFO (0, 0, 0, -1, ""); - WEE_GET_WORD_INFO (0, 0, 1, 1, "a"); - WEE_GET_WORD_INFO (0, 2, 3, 3, "abc"); - WEE_GET_WORD_INFO (2, 4, 5, 3, " abc"); - WEE_GET_WORD_INFO (2, 4, 5, 3, " abc "); - WEE_GET_WORD_INFO (0, 4, 5, 5, "first second"); - WEE_GET_WORD_INFO (1, 5, 6, 5, " first second"); + WEE_GET_WORD_INFO (0, 1, 1, 1, "a"); + WEE_GET_WORD_INFO (0, 3, 3, 3, "abc"); + WEE_GET_WORD_INFO (2, 5, 5, 3, " abc"); + WEE_GET_WORD_INFO (2, 5, 5, 3, " abc "); + WEE_GET_WORD_INFO (0, 5, 5, 5, "first second"); + WEE_GET_WORD_INFO (1, 6, 6, 5, " first second"); - WEE_GET_WORD_INFO (0, -1, 0, 0, "\nabc"); - WEE_GET_WORD_INFO (0, 0, 1, 0, " \nabc"); - WEE_GET_WORD_INFO (0, 1, 2, 0, " \nabc"); - WEE_GET_WORD_INFO (0, 4, 5, 5, "first\nsecond"); + WEE_GET_WORD_INFO (0, 0, 0, 0, "\nabc"); + WEE_GET_WORD_INFO (0, 1, 1, 0, " \nabc"); + WEE_GET_WORD_INFO (0, 2, 2, 0, " \nabc"); + WEE_GET_WORD_INFO (0, 5, 5, 5, "first\nsecond"); snprintf (string, sizeof (string), "%c%c01abc", GUI_COLOR_COLOR_CHAR, GUI_COLOR_FG_CHAR); - WEE_GET_WORD_INFO (4, 6, 3, 3, string); + WEE_GET_WORD_INFO (4, 7, 3, 3, string); snprintf (string, sizeof (string), "abc%c%c01", GUI_COLOR_COLOR_CHAR, GUI_COLOR_FG_CHAR); - WEE_GET_WORD_INFO (0, 6, 3, 3, string); + WEE_GET_WORD_INFO (0, 7, 3, 3, string); snprintf (string, sizeof (string), " %c%c01 abc", GUI_COLOR_COLOR_CHAR, GUI_COLOR_FG_CHAR); - WEE_GET_WORD_INFO (6, 8, 5, 3, string); + WEE_GET_WORD_INFO (6, 9, 5, 3, string); snprintf (string, sizeof (string), "\n%c%c01abc", GUI_COLOR_COLOR_CHAR, GUI_COLOR_FG_CHAR); - WEE_GET_WORD_INFO (0, -1, 0, 0, string); + WEE_GET_WORD_INFO (0, 0, 0, 0, string); snprintf (string, sizeof (string), "%c%c01\nabc", GUI_COLOR_COLOR_CHAR, GUI_COLOR_FG_CHAR); - WEE_GET_WORD_INFO (0, 3, 0, 0, string); + WEE_GET_WORD_INFO (0, 4, 0, 0, string); snprintf (string, sizeof (string), " %c%c01 \nabc", GUI_COLOR_COLOR_CHAR, GUI_COLOR_FG_CHAR); - WEE_GET_WORD_INFO (0, 5, 2, 0, string); + WEE_GET_WORD_INFO (0, 6, 2, 0, string); } /*