kakoune/src
Johannes Altmanninger 22b1d4ec4a Try to fix crash due to fifo read regression
I saw a crash when running

	git log --oneline %arg{@}
	hook -once buffer NormalIdle .* %{
		execute-keys -draft \
		%{gk!} \
		%{git diff --quiet || echo "Unstaged changes";} \
		%{git diff --quiet --cached || echo "Staged changes";} \
		<ret>
	}

Backtrace (I still have GDB attached):

    #4  0x00006502c740b13f in Kakoune::operator- (rhs=..., lhs=...) at /home/johannes/git/kakoune/src/units.hh:33
    33	   { return RealType(lhs.m_value - rhs.m_value); }
    (gdb) up
    #5  Kakoune::Buffer::next (coord=..., this=0x6502c90d7ff0) at /home/johannes/git/kakoune/src/buffer.inl.hh:18
    18	   if (coord.column < m_lines[coord.line].length() - 1)
    (gdb) up
    #6  FifoWatcher::read_fifo (this=0x6502c90d9e48) at buffer_utils.cc:252
    252	                           m_buffer.erase(pos, m_buffer.next(pos));

This was introduced in 582c3c56b (Do not add trailing newline to
non-scrolling fifo buffers, 2024-01-28).

The problem seems to be that we call "m_buffer.next()" on a position
that is past-end the buffer, so m_lines[coord.line] is out-of-bounds.
Fix it.
For some reason I have not managed to reproduce the crash, not even
with sanitize=address.

There might be another problem: m_had_trailing_newline is intentionally
uninitialized because it is supposed to be read only on the second
read() with a positive return value. Unfortunately I think it's
possible that e.g. a NormalIdle hook inserts some text before the
first positive read(). Then, this line

        const bool is_first = pos == BufferCoord{0,0};
        if (not m_scroll and (is_first or m_had_trailing_newline))
            pos = m_buffer.next(pos);

will read uninitialized "m_had_trailing_newline".  Fix that too, to
be on the safe side. Sadly I don't have a test for this one either
so I'm not sure.
2024-02-18 10:14:17 +11:00
..
.gdbinit Embed gdb pretty-printing script directly into Kakoune binary 2019-01-23 20:27:16 +11:00
alias_registry.cc
alias_registry.hh
array_view.hh Support building ArrayView from contigous iterators 2023-11-10 16:35:46 +11:00
assert.cc Display a message on the tty directly on fatal error 2023-11-02 18:16:43 +11:00
assert.hh
backtrace.cc Replace snprintf with format_to 2023-11-05 12:30:54 +11:00
backtrace.hh
buffer_manager.cc Support opening files bigger than 2 GiB 2021-05-28 17:03:41 +10:00
buffer_manager.hh Remove unnecessary forward declaration 2021-07-20 22:30:41 +10:00
buffer_utils.cc Try to fix crash due to fifo read regression 2024-02-18 10:14:17 +11:00
buffer_utils.hh rework selection insert/replace using a for_each method 2021-09-30 20:12:58 +10:00
buffer.cc Fix using invalid strings for undo content strings 2024-01-21 10:24:08 +11:00
buffer.hh Revert "Switch undo storage from a tree to a plain list" 2023-06-17 17:31:57 +10:00
buffer.inl.hh Replace std::strong_ordering with auto return type to not require <compare> 2023-01-21 11:19:39 +11:00
changes.cc
changes.hh Fix pasting after when selections are overlapping 2022-11-28 20:27:44 +11:00
client_manager.cc Remove Window::force_redraw() 2023-08-27 08:03:42 +10:00
client_manager.hh Load buffer in command line order 2022-12-06 17:48:42 +11:00
client.cc Use different hash algorithms for strings and file hashing 2024-02-06 21:57:17 +11:00
client.hh Remove Window::force_redraw() 2023-08-27 08:03:42 +10:00
clock.hh Remove DurationMs and slight code refactor 2018-12-28 06:27:35 +11:00
color.cc Add support for 0-padding in format and replace uses of sprintf 2023-11-03 20:27:41 +11:00
color.hh Remove redundant comparison operators 2023-10-25 20:40:04 +11:00
command_manager.cc Use a separate copy of the command completer for each completion 2023-11-14 21:39:03 +11:00
command_manager.hh Use a separate copy of the command completer for each completion 2023-11-14 21:39:03 +11:00
commands.cc ranked match: prefer input order over alphabetical order for user-specified completions 2023-12-02 10:43:59 +01:00
commands.hh
completion.cc
completion.hh Use a separate copy of the command completer for each completion 2023-11-14 21:39:03 +11:00
constexpr_utils.hh Fix compilation due to failing template deduction for aggregates 2022-04-28 19:34:36 +02:00
context.cc Make selection undo skip over entries that are nop after buffer change 2022-12-27 18:24:55 +01:00
context.hh Default comparison operators that can be 2023-10-25 21:06:52 +11:00
coord.hh Fix warnings with gcc-13 2023-05-21 12:40:27 +10:00
diff.hh Take eq predicate by reference in for_each_diff 2023-12-26 21:21:01 +11:00
display_buffer.cc Trim display lines before the colorize pass 2023-06-12 16:26:22 +10:00
display_buffer.hh Change use of deprecated '->' operator on an iterator 2023-12-10 10:58:42 +00:00
enum.hh Replace std::enable_if with requires 2021-11-21 09:44:56 +11:00
env_vars.cc Do not copy environment strings, just refer to them 2019-03-21 20:43:24 +11:00
env_vars.hh
event_manager.cc Small code style tweak 2023-12-26 18:49:16 +11:00
event_manager.hh Add <c-g> to cancel current operation 2023-05-21 16:20:51 +10:00
exception.cc
exception.hh Add <c-g> to cancel current operation 2023-05-21 16:20:51 +10:00
face_registry.cc Add an InlineInformation face distinct from Information 2023-09-28 15:06:29 +02:00
face_registry.hh Pre-parse face specs in Highlighters 2023-06-10 09:46:46 +10:00
face.hh Default comparison operators that can be 2023-10-25 21:06:52 +11:00
file.cc Use different hash algorithms for strings and file hashing 2024-02-06 21:57:17 +11:00
file.hh Remove redundant comparison operators 2023-10-25 20:40:04 +11:00
flags.hh Default comparison operators that can be 2023-10-25 21:06:52 +11:00
hash_map.cc Fix clang warning regarding useless braces when using HashSet 2022-08-28 15:23:29 +02:00
hash_map.hh Fix use after move in HashMap::insert 2023-11-18 19:07:23 +01:00
hash.cc Use different hash algorithms for strings and file hashing 2024-02-06 21:57:17 +11:00
hash.hh Use different hash algorithms for strings and file hashing 2024-02-06 21:57:17 +11:00
highlighter_group.cc Use menu behavior for add-highlighter/remove-highlighter completion 2022-07-21 16:48:44 +02:00
highlighter_group.hh Rename DefinedHighlighters to SharedHighlighters 2020-08-08 11:19:02 +10:00
highlighter.cc Add -override support to add-highlighter 2020-03-30 21:04:01 +11:00
highlighter.hh Do not make cursor visible after mouse scrolling and view commands 2023-09-02 12:55:57 +10:00
highlighters.cc Support -after switch for flag-lines highlighter 2024-01-30 08:20:13 +11:00
highlighters.hh Default comparison operators that can be 2023-10-25 21:06:52 +11:00
hook_manager.cc Add a ProfileScope helper class to replace most profiling uses 2023-08-13 03:57:46 +10:00
hook_manager.hh Immediately execute ModuleLoaded hooks for already loaded modules 2023-02-14 21:31:29 +11:00
input_handler.cc Mark refresh_ifn() implementation as an override in input_handler.cc 2023-12-10 09:58:40 +00:00
input_handler.hh rc tools menu: replace menu builtin with a prompt-based implementation 2023-11-20 20:47:22 +01:00
insert_completer.cc ranked match: prefer input order over alphabetical order for user-specified completions 2023-12-02 10:43:59 +01:00
insert_completer.hh Default comparison operators that can be 2023-10-25 21:06:52 +11:00
json_ui.cc Add support for 0-padding in format and replace uses of sprintf 2023-11-03 20:27:41 +11:00
json_ui.hh Implement bracketed paste 2023-03-11 16:21:57 +01:00
json.cc Fix compiler warnings when char is unsigned 2023-12-10 11:09:55 +00:00
json.hh Add support for 0-padding in format and replace uses of sprintf 2023-11-03 20:27:41 +11:00
keymap_manager.cc Allow map/unmap during mapping execution 2023-07-20 09:18:23 +02:00
keymap_manager.hh Allow map/unmap during mapping execution 2023-07-20 09:18:23 +02:00
keys.cc Fix debug keys output for shift/ctrl modified mouse events 2023-05-11 20:21:31 +01:00
keys.hh Fix new gcc errors for missing types. 2023-02-28 19:36:44 -08:00
line_modification.cc Default comparison operators that can be 2023-10-25 21:06:52 +11:00
line_modification.hh Default comparison operators that can be 2023-10-25 21:06:52 +11:00
main.cc Merge remote-tracking branch 'krobelus/changelog' 2024-02-10 21:55:09 +11:00
Makefile Add -Wno-stringop-overflow for g++ 2023-12-10 10:26:37 +00:00
memory.cc Track more memory statistics 2019-03-21 20:35:22 +11:00
memory.hh Remove redundant comparison operators 2023-10-25 20:40:04 +11:00
meta.hh
normal.cc Don't modify prompt history when validating empty input 2024-01-15 15:08:10 +01:00
normal.hh Make linewise bracketed paste match P behavior 2023-03-11 16:21:57 +01:00
option_manager.cc Defer deletion of unsetted option to return to main loop 2019-01-20 22:46:40 +11:00
option_manager.hh Add support for removing from options 2020-09-09 21:00:30 +10:00
option_types.cc Use std::remove_cvref instead of std::decay 2021-11-21 09:44:57 +11:00
option_types.hh Replace std::enable_if with requires 2021-11-21 09:44:56 +11:00
option.hh Default comparison operators that can be 2023-10-25 21:06:52 +11:00
optional.hh Remove redundant comparison operators 2023-10-25 20:40:04 +11:00
parameters_parser.cc Complete arguments to "echo -to-file" 2023-02-17 20:50:58 +01:00
parameters_parser.hh Remove redundant comparison operators 2023-10-25 20:40:04 +11:00
profile.hh Add a ProfileScope helper class to replace most profiling uses 2023-08-13 03:57:46 +10:00
range.hh Default comparison operators that can be 2023-10-25 21:06:52 +11:00
ranges.cc Fix compilation due to failing template deduction for aggregates 2022-04-28 19:34:36 +02:00
ranges.hh Default comparison operators that can be 2023-10-25 21:06:52 +11:00
ranked_match.cc Use unicode is_word/to_{lower/upper} function in ranked match 2024-02-12 07:50:04 +11:00
ranked_match.hh ranked match: prefer input order over alphabetical order for user-specified completions 2023-12-02 10:43:59 +01:00
ref_ptr.hh Fix crash when deleting a buffer from a user mapping 2022-04-12 12:49:19 +10:00
regex_impl.cc Remove ignored packed attribute and static_assert on Node size 2023-11-05 12:38:39 +11:00
regex_impl.hh Early reject regex instructions that were already scheduled this step 2024-02-12 08:08:16 +11:00
regex.cc Quote completions of regex options 2023-11-13 23:42:39 +01:00
regex.hh Quote completions of regex options 2023-11-13 23:42:39 +01:00
register_manager.cc Elide temporary vector when completing register names 2022-07-21 16:48:44 +02:00
register_manager.hh Remove stale comment about StaticRegister 2022-08-16 19:15:22 +02:00
remote.cc Do not poll command sockets while shell command is running 2023-11-04 17:48:25 +01:00
remote.hh Add a daemonize-session command and refactor local client handling 2023-09-26 17:50:56 +10:00
safe_ptr.hh Header and dependency cleanup 2019-01-24 21:22:20 +11:00
scope.cc Do not include non-primitive option value in *SetOption hook filter 2020-06-09 21:38:47 +10:00
scope.hh Add override 2019-11-09 12:53:45 -05:00
selection.cc Fix pasting after when selections are overlapping 2022-11-28 20:27:44 +11:00
selection.hh Fix stray semicolon 2023-12-12 21:23:57 +11:00
selectors.cc Add <c-g> to cancel current operation 2023-05-21 16:20:51 +10:00
selectors.hh Ensure that the capture group actually matched in select_matches 2020-09-22 21:14:40 +10:00
shared_string.cc Improve WordDB performance by precomputing hashes 2023-11-17 17:01:51 +11:00
shared_string.hh Improve WordDB performance by precomputing hashes 2023-11-17 17:01:51 +11:00
shell_manager.cc Make shell-script-candidates completer run in the background 2023-11-14 21:39:03 +11:00
shell_manager.hh Fix wrong name 2023-12-26 18:09:25 +11:00
string_utils.cc Add support for 0-padding in format and replace uses of sprintf 2023-11-03 20:27:41 +11:00
string_utils.hh Remove redundant comparison operators 2023-10-25 20:40:04 +11:00
string.cc Improve code-generation for Strings 2021-07-20 22:30:41 +10:00
string.hh Use different hash algorithms for strings and file hashing 2024-02-06 21:57:17 +11:00
terminal_ui.cc Fix compiler warnings when char is unsigned 2023-12-10 11:09:55 +00:00
terminal_ui.hh Skip output synchronization query when explicitly disabled 2023-11-24 12:55:45 +00:00
unicode.hh Avoid iswlower, iswupper, towlower and towupper for ascii codepoints 2024-02-06 22:16:08 +11:00
unique_descriptor.hh Make shell-script-candidates completer run in the background 2023-11-14 21:39:03 +11:00
unit_tests.cc Remove posB from information given by the diff algorithm 2020-03-20 20:27:50 +11:00
unit_tests.hh
units.hh Revert "Remove compare include that seems to break clang" 2023-01-21 11:27:05 +11:00
user_interface.hh Implement bracketed paste 2023-03-11 16:21:57 +01:00
utf8_iterator.hh Remove redundant comparison operators 2023-10-25 20:40:04 +11:00
utf8.hh Rank a word-boundary after a non-word-boundary 2019-09-07 22:53:29 +02:00
utils.hh Clang is still unhappy, trying another approach with defining my own concept 2021-11-25 22:32:10 +11:00
value.hh Avoid extra indirection for storing FifoWatcher 2023-02-10 12:56:32 +11:00
vector.hh Only redraw updated lines 2021-07-12 10:25:58 +10:00
window.cc Always ensure we do not scroll past the last line 2023-11-01 17:24:54 +11:00
window.hh Use last display setup instead of recomputing for window_range 2023-09-08 05:24:56 +10:00
word_db.cc Improve WordDB performance by precomputing hashes 2023-11-17 17:01:51 +11:00
word_db.hh Speed up WordSplitter 2023-10-25 12:52:14 +11:00