Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running scc --min crash with divide by zero error #223

Closed
viblo opened this issue Jan 26, 2021 · 11 comments
Closed

Running scc --min crash with divide by zero error #223

viblo opened this issue Jan 26, 2021 · 11 comments
Labels
bug Something isn't working

Comments

@viblo
Copy link

viblo commented Jan 26, 2021

Describe the bug
Running scc with the --min argument on my code base results in a divide by zero error

panic: runtime error: integer divide by zero

goroutine 36 [running]:
github.com/boyter/scc/processor.CountStats(0xc0020fbe00)
        /Users/bb100123/Documents/kablamo/scc/processor/workers.go:578 +0x1547
github.com/boyter/scc/processor.processFile(0xc0020fbe00, 0xc0026026c0)
        /Users/bb100123/Documents/kablamo/scc/processor/workers.go:731 +0x139
github.com/boyter/scc/processor.fileProcessorWorker.func1(0xc0000a0180, 0xc000200000, 0xc000200008, 0xc000200010, 0xc0000a01e0, 0xc000200020)
        /Users/bb100123/Documents/kablamo/scc/processor/workers.go:660 +0x2f8
created by github.com/boyter/scc/processor.fileProcessorWorker
        /Users/bb100123/Documents/kablamo/scc/processor/workers.go:631 +0x105

To Reproduce

Unfortunately I cant share the code thats causing this (2m+ lines of company code), hopefully you will get some clue by the stack trace.

I run scc --min or scc --min-gen. I tried some other options and they work as expected..

Expected behavior

No crash :)

Desktop (please complete the following information):

  • OS: Windows
  • Version: 2.13.0

ps. SCC is great, just found it the other day while looking for easy to install and fast alternative to cloc, thanks!

@boyter boyter added the bug Something isn't working label Jan 26, 2021
boyter added a commit that referenced this issue Jan 26, 2021
@boyter
Copy link
Owner

boyter commented Jan 26, 2021

Wow I don't even know how to replicate that... although I know where it occurs.

if !isGenerated && Minified {
    avgLineByteCount := len(fileJob.Content) / int(fileJob.Lines)
    minifiedGeneratedCheck(avgLineByteCount, fileJob)
}

It only happens because somehow the number of lines is zero, and yet... that should never happen because any content would indicate there is at least one line! It's possible, its a file consisting of just null bytes or some such though I guess.

Anyway will I try to replicate that, I have put in a fix on master. If you are able to build from there that should resolve the issue. Otherwise let me know and I can put a build here for you to try. I won't be pushing out the next build till the next version of Go is released so I can get builds for the new M1 Apple machines done at the same time.

@viblo
Copy link
Author

viblo commented Jan 26, 2021

After reading your comment I noticed that I have 0 lines of RestructuredText, because of a README.rst file without any content. However, it doesnt crash (using the 2.13.0 version) if I just scan that file. I will try with your updated code next, just have to update my go install first.

@viblo
Copy link
Author

viblo commented Jan 26, 2021

I tried the latest master, and no more error when running with --min or related arguments. Thanks for the super quick response!

@boyter
Copy link
Owner

boyter commented Jan 26, 2021

Great! No worries at all. Thank's for reporting it so well allowing me to fix it quickly. Hope it unblocks you from whatever you were working on.

@boyter boyter closed this as completed Jan 26, 2021
@danadalleh
Copy link

Ok

@boyter
Copy link
Owner

boyter commented Jan 29, 2021

@danadalleh glad it works for you too

@ghost
Copy link

ghost commented Feb 20, 2021

Would reopen the issue as I have the exact same problem using the latest scc 2.13.0 version and tracked it down when it happens:

  1. Create a folder with a single file (Test > test.txt)
  2. File test.txt is empty but has a UTF-8-BOM encoding (I just used notepad++ to change the file encoding)
  3. Execute scc --min or scc --no-min-gen throws an exception:
panic: runtime error: integer divide by zero

goroutine 11 [running]:
github.com/boyter/scc/processor.CountStats(0xc0000b0000)
        /Users/bb100123/Documents/kablamo/scc/processor/workers.go:578 +0x1547
github.com/boyter/scc/processor.processFile(0xc0000b0000, 0xc00008e0b0)
        /Users/bb100123/Documents/kablamo/scc/processor/workers.go:731 +0x139
github.com/boyter/scc/processor.fileProcessorWorker.func1(0xc000044360, 0xc0001e3fb0, 0xc0001e3fb8, 0xc0001e3fc0, 0xc0000443c0, 0xc0001e3fd0)
        /Users/bb100123/Documents/kablamo/scc/processor/workers.go:660 +0x2f8
created by github.com/boyter/scc/processor.fileProcessorWorker
        /Users/bb100123/Documents/kablamo/scc/processor/workers.go:631 +0x105

Everything works when the file is UTF-8 encoded.

EDIT: Just read @boyter comment at the top stating that it should be fixed on master. Is there a way to get a prerelease version of 3.0 now? Sorry for the inconvenience.

@boyter
Copy link
Owner

boyter commented Feb 21, 2021

Ah now that's interesting. The BOM of UTF-8 file. I might have another look to ensure this is resolved, but I suspect it will be. Might explain some other issues though so worth investigating again.

@boyter boyter reopened this Feb 21, 2021
@boyter
Copy link
Owner

boyter commented Feb 22, 2021

Confirmed that this is indeed resolved on master.

You get interesting output,

$ scc
───────────────────────────────────────────────────────────────────────────────
Language                 Files     Lines   Blanks  Comments     Code Complexity
───────────────────────────────────────────────────────────────────────────────
Plain Text                   1         0        0         0        0          0
───────────────────────────────────────────────────────────────────────────────
Total                        1         0        0         0        0          0
───────────────────────────────────────────────────────────────────────────────
Estimated Cost to Develop (organic) $0
Estimated Schedule Effort (organic) 0.000000 months
Estimated People Required 1 Grandparent
───────────────────────────────────────────────────────────────────────────────
Processed 3 bytes, 0.000 megabytes (SI)
───────────────────────────────────────────────────────────────────────────────

Because it shows scc processing 3 bytes, but that file having literally nothing in it. Which is correct for a BOM file. Anyway appears still to be resolved.

@d-bauer Pretty sure you are using Windows. Attached a build for you which should fix this for you. Its pretty stable, just not finished for 3.0.0 yet.

scc-3.0.0-x86_64-pc-windows.zip

@boyter boyter closed this as completed Feb 22, 2021
@ghost
Copy link

ghost commented Feb 23, 2021

@boyter Thank you very much for your quick response. Yes I use windows, thanks for the provided version. I appreciate it 👍

@boyter
Copy link
Owner

boyter commented Feb 23, 2021

@d-bauer No worries at all. In fact you can even get the real 3.0.0 release now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants