panic: runtime error: invalid memory address or nil pointer dereference when using --no-duplicates
Describe the bug When I use --no-duplicates, I always receive the following error: `panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x5f4adb]
goroutine 41 [running]: github.com/boyter/scc/processor.processFile(0xc000b05e00) /home/susof/go/pkg/mod/github.com/boyter/[email protected]/processor/workers.go:450 +0x31b github.com/boyter/scc/processor.fileProcessorWorker.func1() /home/susof/go/pkg/mod/github.com/boyter/[email protected]/processor/workers.go:375 +0x3f3 created by github.com/boyter/scc/processor.fileProcessorWorker /home/susof/go/pkg/mod/github.com/boyter/[email protected]/processor/workers.go:346 +0x78 `
To Reproduce
- Using command line scc
- arguments: -d or --no-duplicates
- it crashes before counting occur
Expected behavior Count lines and calculate cocomo excluding duplicate files.
Desktop (please complete the following information): OS: linux scc version 3.0.0
Unable to reproduce locally... possibly related to this? https://github.com/boyter/scc/issues/260
Are you able to provide a file that causes this?
Found it. Running scc -d -t I found this empty file, "blank.php", .It seems related to #260 .
➜ paginas git:(master) scc -t -d
TRACE 2022-02-24T22:01:11Z: milliseconds unmarshal: 1
TRACE 2022-02-24T22:01:11Z: nanoseconds build extension to language: 134320
TRACE 2022-02-24T22:01:11Z: configured to lazy load language features
TRACE 2022-02-24T22:01:11Z: nanoseconds to build language PHP features: 95767
TRACE 2022-02-24T22:01:11Z: nanoseconds read into memory: fechar.php: 116106
TRACE 2022-02-24T22:01:11Z: state transition @ 1:0: line=code state=code
TRACE 2022-02-24T22:01:11Z: state transition @ 1:4: line=code state=code
] ended with state: code: counted as codene 1 [<?
TRACE 2022-02-24T22:01:11Z: state transition @ 2:1: line=code state=code
TRACE 2022-02-24T22:01:11Z: nanoseconds read into memory: processual/decisaoPresidente/listaDecisoes.php: 29783
TRACE 2022-02-24T22:01:11Z: nanoseconds read into memory: index.php: 38869
TRACE 2022-02-24T22:01:11Z: state transition @ 1:0: line=code state=code
TRACE 2022-02-24T22:01:11Z: nanoseconds read into memory: vitusDigital/relatorio/quantitativoProcessos.php: 52334
TRACE 2022-02-24T22:01:11Z: state transition @ 1:6: line=code state=code
TRACE 2022-02-24T22:01:11Z: state transition @ 1:0: line=code state=code
] ended with state: code: counted as codecisaoPresidente/listaDecisoes.php line 1 [<?php
TRACE 2022-02-24T22:01:11Z: state transition @ 1:76: line=code state=code
TRACE 2022-02-24T22:01:11Z: nanoseconds read into memory: blank.php: 19887
TRACE 2022-02-24T22:01:11Z: index.php line 1 [<img id="imagem" src="./arquivos/imagens/stj.jpg"; width="95%" height="95%"] ended with state: code: counted as code
TRACE 2022-02-24T22:01:11Z: state transition @ 1:0: line=code state=code
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x5f4adb]
goroutine 11 [running]:
github.com/boyter/scc/processor.processFile(0xc000468000)
/home/susof/go/pkg/mod/github.com/boyter/[email protected]/processor/workers.go:450 +0x31b
github.com/boyter/scc/processor.fileProcessorWorker.func1()
/home/susof/go/pkg/mod/github.com/boyter/[email protected]/processor/workers.go:375 +0x3f3
created by github.com/boyter/scc/processor.fileProcessorWorker
/home/susof/go/pkg/mod/github.com/boyter/[email protected]/processor/workers.go:346 +0x78
Cheers. Should be able to track it down and resolve then.
So have been trying to replicate this without success.
I have tried empty files both with and without UTF-8 BOM with other files around it.
Are you able to provide a test case that actually does this? Just putting a blank file somewhere is not enough to trigger it, unless there is something I am missing here.
paginas.tar.gz
Those are the files that does it. If I rm blank.php, the problem goes away.
Sorry, I went on vacation.
Thanks. Should be able to track it down now.
OK. This does not work on the latest version of master, for me.
@robertoberlim I noticed you are using version 3.0.0, would you be happy to try a build from master? This should establish if it was resolved through something I did, the version of Go I compiled, or if it's possibly related to your system.
I have included a build for you to try below, but building from master should produce the same result, hashes here just in case.
$ hashit scc
scc (5259264 bytes)
MD5 00a40fcd7a4f3956a457ff6d5432aebe
SHA1 ea128523d5eb22218f4dee0d144bf6a6ae04a6a0
SHA256 1aab3b3120cab3c8a39b3a680663081eb3313205483df03f6570fe7f0adee1b3
SHA512 ad877ef886f48f52783e5508addb36a0f4c6ed010b3643214d47cfb642ef4fef45111d83509dce9eeb25d6905e4ebb4982667486a01f82fd83c0a1c535a7a8f6
I tried a build from master (GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" ) using go version go1.17.8 linux/amd64. worked flawlessly.
> ~/codebase/scc/scc -d -t
TRACE 2022-03-10T19:22:13Z: milliseconds unmarshal: 1
TRACE 2022-03-10T19:22:13Z: nanoseconds build extension to language: 107688
TRACE 2022-03-10T19:22:13Z: configured to lazy load language features
TRACE 2022-03-10T19:22:13Z: nanoseconds to build language PHP features: 32686
TRACE 2022-03-10T19:22:13Z: nanoseconds to build language #! features: 25834
TRACE 2022-03-10T19:22:13Z: nanoseconds read into memory: fechar.php: 24051
TRACE 2022-03-10T19:22:13Z: fechar.php line 1 ended with state: 1: counted as code
TRACE 2022-03-10T19:22:13Z: fechar.php line 2 ended with state: 1: counted as code
TRACE 2022-03-10T19:22:13Z: fechar.php line 3 ended with state: 1: counted as code
TRACE 2022-03-10T19:22:13Z: fechar.php line 4 ended with state: 1: counted as code
TRACE 2022-03-10T19:22:13Z: fechar.php line 5 ended with state: 1: counted as code
TRACE 2022-03-10T19:22:13Z: fechar.php line 6 ended with state: 1: counted as code
TRACE 2022-03-10T19:22:13Z: fechar.php line 7 ended with state: 1: counted as code
TRACE 2022-03-10T19:22:13Z: nanoseconds read into memory: index.php: 35998
TRACE 2022-03-10T19:22:13Z: index.php line 1 ended with state: 1: counted as code
TRACE 2022-03-10T19:22:13Z: nanoseconds process: index.php: 10228
TRACE 2022-03-10T19:22:13Z: fechar.php line 8 ended with state: 1: counted as code
TRACE 2022-03-10T19:22:13Z: fechar.php line 9 ended with state: 1: counted as code
TRACE 2022-03-10T19:22:13Z: fechar.php line 10 ended with state: 1: counted as code
TRACE 2022-03-10T19:22:13Z: fechar.php line 11 ended with state: 1: counted as code
TRACE 2022-03-10T19:22:13Z: fechar.php line 12 ended with state: 1: counted as code
TRACE 2022-03-10T19:22:13Z: fechar.php line 13 ended with state: 1: counted as code
TRACE 2022-03-10T19:22:13Z: fechar.php line 14 ended with state: 1: counted as code
TRACE 2022-03-10T19:22:13Z: fechar.php line 15 ended with state: 1: counted as code
TRACE 2022-03-10T19:22:13Z: fechar.php line 16 ended with state: 1: counted as code
TRACE 2022-03-10T19:22:13Z: fechar.php line 17 ended with state: 1: counted as code
TRACE 2022-03-10T19:22:13Z: fechar.php line 18 ended with state: 1: counted as blank
TRACE 2022-03-10T19:22:13Z: fechar.php line 19 ended with state: 1: counted as code
TRACE 2022-03-10T19:22:13Z: fechar.php line 20 ended with state: 1: counted as code
TRACE 2022-03-10T19:22:13Z: fechar.php line 21 ended with state: 1: counted as code
TRACE 2022-03-10T19:22:13Z: nanoseconds process: fechar.php: 104300
TRACE 2022-03-10T19:22:13Z: nanoseconds read into memory: scc: 1534704
───────────────────────────────────────────────────────────────────────────────
Language Files Lines Blanks Comments Code Complexity
───────────────────────────────────────────────────────────────────────────────
PHP 2 22 1 0 21 0
───────────────────────────────────────────────────────────────────────────────
Total 2 22 1 0 21 0
───────────────────────────────────────────────────────────────────────────────
Estimated Cost to Develop (organic) $467
Estimated Schedule Effort (organic) 0,75 months
Estimated People Required (organic) 0,06
───────────────────────────────────────────────────────────────────────────────
Processed 755 bytes, 0.001 megabytes (SI)
───────────────────────────────────────────────────────────────────────────────
I also tried using your build. No problems whatsoever.
> ./scc -d -t
TRACE 2022-03-10T19:23:45Z: milliseconds unmarshal: 0
TRACE 2022-03-10T19:23:45Z: nanoseconds build extension to language: 54707
TRACE 2022-03-10T19:23:45Z: configured to lazy load language features
TRACE 2022-03-10T19:23:45Z: nanoseconds to build language PHP features: 25961
TRACE 2022-03-10T19:23:45Z: nanoseconds to build language #! features: 66845
TRACE 2022-03-10T19:23:45Z: nanoseconds read into memory: fechar.php: 44428
TRACE 2022-03-10T19:23:45Z: fechar.php line 1 ended with state: 1: counted as code
TRACE 2022-03-10T19:23:45Z: fechar.php line 2 ended with state: 1: counted as code
TRACE 2022-03-10T19:23:45Z: fechar.php line 3 ended with state: 1: counted as code
TRACE 2022-03-10T19:23:45Z: fechar.php line 4 ended with state: 1: counted as code
TRACE 2022-03-10T19:23:45Z: fechar.php line 5 ended with state: 1: counted as code
TRACE 2022-03-10T19:23:45Z: fechar.php line 6 ended with state: 1: counted as code
TRACE 2022-03-10T19:23:45Z: fechar.php line 7 ended with state: 1: counted as code
TRACE 2022-03-10T19:23:45Z: fechar.php line 8 ended with state: 1: counted as code
TRACE 2022-03-10T19:23:45Z: fechar.php line 9 ended with state: 1: counted as code
TRACE 2022-03-10T19:23:45Z: fechar.php line 10 ended with state: 1: counted as code
TRACE 2022-03-10T19:23:45Z: fechar.php line 11 ended with state: 1: counted as code
TRACE 2022-03-10T19:23:45Z: fechar.php line 12 ended with state: 1: counted as code
TRACE 2022-03-10T19:23:45Z: fechar.php line 13 ended with state: 1: counted as code
TRACE 2022-03-10T19:23:45Z: fechar.php line 14 ended with state: 1: counted as code
TRACE 2022-03-10T19:23:45Z: fechar.php line 15 ended with state: 1: counted as code
TRACE 2022-03-10T19:23:45Z: fechar.php line 16 ended with state: 1: counted as code
TRACE 2022-03-10T19:23:45Z: fechar.php line 17 ended with state: 1: counted as code
TRACE 2022-03-10T19:23:45Z: fechar.php line 18 ended with state: 1: counted as blank
TRACE 2022-03-10T19:23:45Z: fechar.php line 19 ended with state: 1: counted as code
TRACE 2022-03-10T19:23:45Z: fechar.php line 20 ended with state: 1: counted as code
TRACE 2022-03-10T19:23:45Z: fechar.php line 21 ended with state: 1: counted as code
TRACE 2022-03-10T19:23:45Z: nanoseconds process: fechar.php: 67290
TRACE 2022-03-10T19:23:45Z: nanoseconds read into memory: index.php: 19946
TRACE 2022-03-10T19:23:45Z: index.php line 1 ended with state: 1: counted as code
TRACE 2022-03-10T19:23:45Z: nanoseconds process: index.php: 9021
TRACE 2022-03-10T19:23:45Z: nanoseconds read into memory: scc: 1516657
───────────────────────────────────────────────────────────────────────────────
Language Files Lines Blanks Comments Code Complexity
───────────────────────────────────────────────────────────────────────────────
PHP 2 22 1 0 21 0
───────────────────────────────────────────────────────────────────────────────
Total 2 22 1 0 21 0
───────────────────────────────────────────────────────────────────────────────
Estimated Cost to Develop (organic) $467
Estimated Schedule Effort (organic) 0,75 months
Estimated People Required (organic) 0,06
───────────────────────────────────────────────────────────────────────────────
Processed 755 bytes, 0.001 megabytes (SI)
───────────────────────────────────────────────────────────────────────────────
BTW, I tried
> go install github.com/boyter/scc@master
roberto@cjf020282:pts/9->/home/roberto (0)
> scc --version
scc version 3.0.0
Shouldn't upgrade to 3.1.0?
Right so next build should resolve this. Thats good at least.
As for building from master... yes I would have thought so but the same result for me. I am befuddled by Go's install logic.
Anyway it should make the next release at least.
This should work now with a go install as I switched to goreleaser which requires the tags setup correctly.