Skip to content

Commit

Permalink
resolve #260
Browse files Browse the repository at this point in the history
  • Loading branch information
boyter committed May 13, 2021
1 parent 9ff7d9c commit cb04a8d
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 72 deletions.
2 changes: 1 addition & 1 deletion LANGUAGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ Verilog (vg,vh,v)
Verilog Args File (irunargs,xrunargs)
Vertex Shader File (vsh)
VHDL (vhd,vhdl)
Vim Script (vim)
Vim Script (vim,vimrc,gvimrc,_vimrc,.vimrc,_gvimrc,.gvimrc,vimrc,gvimrc)
Visual Basic (vb)
Visual Basic for Applications (cls)
Vue (vue)
Expand Down
147 changes: 87 additions & 60 deletions SCC-OUTPUT-REPORT.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
</tr></thead>
<tbody><tr>
<th>Go</th>
<th>34</th>
<th>8548</th>
<th>1396</th>
<th>398</th>
<th>6754</th>
<th>1392</th>
<th>335679</th>
<th>43</th>
<th>8670</th>
<th>1437</th>
<th>404</th>
<th>6829</th>
<th>1377</th>
<th>337105</th>
</tr><tr>
<th>Java</th>
<th>24</th>
Expand All @@ -39,21 +39,21 @@
</tr><tr>
<th>Markdown</th>
<th>11</th>
<th>1275</th>
<th>309</th>
<th>1282</th>
<th>312</th>
<th>0</th>
<th>966</th>
<th>970</th>
<th>0</th>
<th>52209</th>
<th>52379</th>
</tr><tr>
<th>Python</th>
<th>9</th>
<th>350</th>
<th>20</th>
<th>20</th>
<th>310</th>
<th>32</th>
<th>10072</th>
<th>10</th>
<th>368</th>
<th>31</th>
<th>198</th>
<th>139</th>
<th>53</th>
<th>10706</th>
</tr><tr>
<th>CSS</th>
<th>5</th>
Expand All @@ -74,13 +74,13 @@
<th>3425</th>
</tr><tr>
<th>YAML</th>
<th>4</th>
<th>78</th>
<th>5</th>
<th>482</th>
<th>13</th>
<th>20</th>
<th>45</th>
<th>21</th>
<th>448</th>
<th>0</th>
<th>2153</th>
<th>7372</th>
</tr><tr>
<th>gitignore</th>
<th>4</th>
Expand All @@ -93,21 +93,39 @@
</tr><tr>
<th>Shell</th>
<th>3</th>
<th>1073</th>
<th>142</th>
<th>84</th>
<th>847</th>
<th>1084</th>
<th>144</th>
<th>86</th>
<th>854</th>
<th>94</th>
<th>38597</th>
<th>39018</th>
</tr><tr>
<th>C#</th>
<th>2</th>
<th>623</th>
<th>58</th>
<th>73</th>
<th>492</th>
<th>26</th>
<th>83</th>
<th>130</th>
<th>410</th>
<th>45</th>
<th>19739</th>
</tr><tr>
<th>HTML</th>
<th>2</th>
<th>1216</th>
<th>0</th>
<th>0</th>
<th>1216</th>
<th>0</th>
<th>17758</th>
</tr><tr>
<th>JSON</th>
<th>2</th>
<th>7230</th>
<th>0</th>
<th>0</th>
<th>7230</th>
<th>0</th>
<th>110403</th>
</tr><tr>
<th>JavaServer Pages</th>
<th>2</th>
Expand Down Expand Up @@ -207,6 +225,15 @@
<th>139</th>
<th>1</th>
<th>6900</th>
</tr><tr>
<th>C</th>
<th>1</th>
<th>0</th>
<th>0</th>
<th>0</th>
<th>0</th>
<th>0</th>
<th>0</th>
</tr><tr>
<th>C Header</th>
<th>1</th>
Expand All @@ -225,6 +252,15 @@
<th>1</th>
<th>0</th>
<th>6</th>
</tr><tr>
<th>CSV</th>
<th>1</th>
<th>66</th>
<th>0</th>
<th>0</th>
<th>66</th>
<th>0</th>
<th>1754</th>
</tr><tr>
<th>Clojure</th>
<th>1</th>
Expand Down Expand Up @@ -360,24 +396,6 @@
<th>10</th>
<th>0</th>
<th>245</th>
</tr><tr>
<th>HTML</th>
<th>1</th>
<th>581</th>
<th>0</th>
<th>0</th>
<th>581</th>
<th>0</th>
<th>8510</th>
</tr><tr>
<th>JSON</th>
<th>1</th>
<th>7206</th>
<th>0</th>
<th>0</th>
<th>7206</th>
<th>0</th>
<th>100328</th>
</tr><tr>
<th>Korn Shell</th>
<th>1</th>
Expand Down Expand Up @@ -459,6 +477,15 @@
<th>0</th>
<th>0</th>
<th>0</th>
</tr><tr>
<th>SQL</th>
<th>1</th>
<th>204</th>
<th>0</th>
<th>0</th>
<th>204</th>
<th>0</th>
<th>23687</th>
</tr><tr>
<th>Sieve</th>
<th>1</th>
Expand Down Expand Up @@ -526,9 +553,9 @@
<th>Wren</th>
<th>1</th>
<th>188</th>
<th>22</th>
<th>35</th>
<th>131</th>
<th>26</th>
<th>37</th>
<th>125</th>
<th>8</th>
<th>3544</th>
</tr><tr>
Expand Down Expand Up @@ -570,12 +597,12 @@
</tr></tbody>
<tfoot><tr>
<th>Total</th>
<th>168</th>
<th>25795</th>
<th>2957</th>
<th>1718</th>
<th>21120</th>
<th>2343</th>
<th>1779796</th>
<th>184</th>
<th>27286</th>
<th>3043</th>
<th>1964</th>
<th>22279</th>
<th>2368</th>
<th>1832430</th>
</tr></tfoot>
</table></body></html>
Empty file added examples/ignore/ignorefile.txt
Empty file.
Empty file added examples/issue260/test.c
Empty file.
21 changes: 10 additions & 11 deletions processor/workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ package processor
import (
"bytes"
"fmt"
"github.com/minio/blake2b-simd"
"runtime/debug"
"strings"
"sync"
"sync/atomic"

"github.com/minio/blake2b-simd"
)

// The below are used as identifiers for the code state machine
Expand Down Expand Up @@ -155,6 +154,15 @@ func verifyIgnoreEscape(langFeatures *LanguageFeature, fileJob *FileJob, index i
// Newlines belong to the line they started on so a file of \n means only 1 line
// This is the 'hot' path for the application and needs to be as fast as possible
func CountStats(fileJob *FileJob) {
// For determining duplicates we need the below. The reason for creating
// the byte array here is to avoid GC pressure. MD5 is in the standard library
// and is fast enough to not warrant murmur3 hashing. No need to be
// crypto secure here either so no need to eat the performance cost of a better
// hash method
if Duplicates {
fileJob.Hash = blake2b.New256()
}

// If the file has a length of 0 it is is empty then we say it has no lines
if fileJob.Bytes == 0 {
fileJob.Lines = 0
Expand Down Expand Up @@ -185,15 +193,6 @@ func CountStats(fileJob *FileJob) {
var lineType LineType
var currentState State = &StateBlank{}

// For determining duplicates we need the below. The reason for creating
// the byte array here is to avoid GC pressure. MD5 is in the standard library
// and is fast enough to not warrant murmur3 hashing. No need to be
// crypto secure here either so no need to eat the performance cost of a better
// hash method
if Duplicates {
fileJob.Hash = blake2b.New256()
}

for index := checkBomSkip(fileJob); index < int(fileJob.Bytes); index++ {
// Based on our current state determine if the state should change by checking
// what the character is. The below is very CPU bound so need to be careful if
Expand Down
11 changes: 11 additions & 0 deletions test-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,17 @@ else
echo -e "${GREEN}PASSED hidden directory${NC}"
fi


# Regression issue https://github.com/boyter/scc/issues/260
if ./scc -d "examples/issue260/" 2>&1 >/dev/null | grep -q "invalid memory address" ; then
echo -e "${RED}======================================================="
echo -e "FAILED duplicate empty crash"
echo -e "=======================================================${NC}"
exit
else
echo -e "${GREEN}PASSED duplicate empty crash${NC}"
fi

a=$(./scc | grep Total)
b=$(./scc --no-ignore | grep Total)
if [ "$a" == "$b" ]; then
Expand Down

0 comments on commit cb04a8d

Please sign in to comment.