Safety check for EOF
@@ -469,6 +469,13 @@ func CountStats(fileJob *FileJob) {
}
}
+ // We shouldn't normally need this, but unclosed strings or comments
+ // might leave the index past the end of the file when we reach this
+ // point.
+ if index >= len(fileJob.Content) {
+ return
+ }
+
// Only check the first 10000 characters for null bytes indicating a binary file
// and if we find it then we return otherwise carry on and ignore binary markers
if index < 10000 && fileJob.Binary {
