From 88243b846adc61c3e34a60f4c0ae53e3eb8b9e93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Sun, 16 Aug 2015 22:26:33 +0200 Subject: [PATCH 1/3] Use right variable name to avoid zero-length array This fixes the typographic error that always assigned an undefined array to `$names`, which made `$list_size` = 0 and triggered a divide by zero error on the next line. --- plugins/emoji/emoji.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/emoji/emoji.plugin.zsh b/plugins/emoji/emoji.plugin.zsh index a98d0b71..adb11bb5 100644 --- a/plugins/emoji/emoji.plugin.zsh +++ b/plugins/emoji/emoji.plugin.zsh @@ -255,7 +255,7 @@ function random_emoji() { if [[ -z "$group" || "$group" == "all" ]]; then names=(${(k)emoji}) else - names=(${=emoji_groups[$group_name]}) + names=(${=emoji_groups[$group]}) fi local list_size=$#names local random_index=$(( ( RANDOM % $list_size ) + 1 )) From c6a5f6efb434fa64f31b40f366e7fecae80758e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Sun, 16 Aug 2015 22:30:56 +0200 Subject: [PATCH 2/3] Check that list_size value is not zero before division --- plugins/emoji/emoji.plugin.zsh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/emoji/emoji.plugin.zsh b/plugins/emoji/emoji.plugin.zsh index adb11bb5..f2d169bf 100644 --- a/plugins/emoji/emoji.plugin.zsh +++ b/plugins/emoji/emoji.plugin.zsh @@ -257,7 +257,8 @@ function random_emoji() { else names=(${=emoji_groups[$group]}) fi - local list_size=$#names + local list_size=${#names} + [[ $list_size -eq 0 ]] && return 1 local random_index=$(( ( RANDOM % $list_size ) + 1 )) local name=${names[$random_index]} echo ${emoji[$name]} From be667a24b0dc6a42a3e5368727366449b09633d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Mon, 17 Aug 2015 01:05:37 +0200 Subject: [PATCH 3/3] Remove obsolete comment --- plugins/emoji/emoji.plugin.zsh | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/emoji/emoji.plugin.zsh b/plugins/emoji/emoji.plugin.zsh index f2d169bf..7876f1c8 100644 --- a/plugins/emoji/emoji.plugin.zsh +++ b/plugins/emoji/emoji.plugin.zsh @@ -76,8 +76,6 @@ emoji_skintone[6]=$'\U1F3FF' # These are stored in a single associative array, $emoji_groups, to avoid cluttering up the global # namespace, and to allow adding additional group definitions at run time. # The keys are the group names, and the values are whitespace-separated lists of emoji character names. -# -# These extra local arrays are used to allow more convenient formatting of the source code. emoji_groups[fruits]=" tomato