clipmenu

Simple clipboard management using dmenu
git clone https://git.sinitax.com/cdown/clipmenu
Log | Files | Refs | README | LICENSE | sfeed.txt

commit d24b57c9db6a51c63dbd094feac42e4a1cf0b7c9
parent 5b596aaf465226b7228ca2e09571b8ddc00566f6
Author: Chris Down <chris@chrisdown.name>
Date:   Tue, 24 Mar 2020 17:34:02 +0000

clipmenud: Fix potential misaligned truncation in duplicate detection

If we detect a duplicate for this selection, but another selection has
already been written, we will truncate the wrong length in the line.

Diffstat:
Mclipmenud | 20++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/clipmenud b/clipmenud @@ -81,8 +81,7 @@ exec {session_lock_fd}> "$session_lock_file" flock -x -n "$session_lock_fd" || die 2 "Can't lock session file -- is another clipmenud running?" -declare -A last_data -declare -A last_cache_file_output +declare -A last_data_sel command -v clipnotify >/dev/null 2>&1 || die 2 "clipnotify not in PATH" command -v xdotool >/dev/null 2>&1 && has_xdotool=1 @@ -118,15 +117,15 @@ while true; do data=${data%x} # avoid trailing newlines being stripped [[ $data == *[^[:space:]]* ]] || continue - [[ ${last_data[$selection]} == "$data" ]] && continue + [[ $last_data == "$data" ]] && continue + [[ ${last_data_sel[$selection]} == "$data" ]] && continue - possible_partial=${last_data[$selection]} - if [[ $possible_partial && $data == "$possible_partial"* ]] || - [[ $possible_partial && $data == *"$possible_partial" ]]; then + if [[ $last_data && $data == "$last_data"* ]] || + [[ $last_data && $data == *"$last_data" ]]; then # Don't actually remove the file yet, because it might be # referenced by an older entry. These will be dealt with at vacuum. - debug "$selection: $possible_partial is a possible partial of $data" - previous_size=$(wc -c <<< "${last_cache_file_output[$selection]}") + debug "$selection: $last_data is a possible partial of $data" + previous_size=$(wc -c <<< "$last_cache_file_output") truncate -s -"$previous_size" "$cache_file" fi @@ -135,8 +134,9 @@ while true; do cache_file_output="$(date +%s%N) $first_line" filename="$cache_dir/$(cksum <<< "$first_line")" - last_cache_file_output[$selection]=$cache_file_output - last_data[$selection]=$data + last_cache_file_output=$cache_file_output + last_data=$data + last_data_sel[$selection]=$data debug "Writing $data to $filename" printf '%s' "$data" > "$filename"