From 6b84b35ec047d87ec81d9916443756964ce24fcb Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Tue, 23 Sep 2014 10:11:15 -0700 Subject: [PATCH] Don't crash on empty files with -f gcc. --- shellcheck.hs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/shellcheck.hs b/shellcheck.hs index 1f0b8c4..8640bf4 100644 --- a/shellcheck.hs +++ b/shellcheck.hs @@ -237,7 +237,12 @@ makeNonVirtual comments contents = map fix comments where ls = lines contents - fix c = c { scColumn = real (ls !! (scLine c - 1)) 0 0 (scColumn c) } + fix c = c { + scColumn = + if scLine c > 0 && scLine c <= length ls + then real (ls !! (scLine c - 1)) 0 0 (scColumn c) + else scColumn c + } real _ r v target | target <= v = r real [] r v _ = r -- should never happen real ('\t':rest) r v target =