LiJiefei / codesearch

Automatically exported from code.google.com/p/codesearch
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

cgrep blows up when given no arguments #9

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. run cgrep
2.
3.

What is the expected output? What do you see instead?
There is a custom usage message which is not displayed.  Instead we get the 
default usage message and a panic.

laptop$ cgrep
Usage of cgrep:
  -c=false: print match counts only
  -cpuprofile="": write cpu profile to this file
  -h=false: omit file names
  -i=false: case-insensitive match
  -l=false: list matching files only
  -n=false: show line numbers
panic: runtime error: index out of range

goroutine 1 [running]:
main.main()
    /[XXXXX]/src/code.google.com/p/codesearch/cmd/cgrep/cgrep.go:58 +0x292

What version of the product are you using? On what operating system?
070ef10ab799 tip. Darwin 10.8.0

Please provide any additional information below.
This is the default flag.Usage() message instead of the custom usage() one 
which exits and would prevent the index-out-of-range error.

The fix is a one-line patch in main():
   flag.Usage = usage

Alternately, we could call our usage() function instead of flag.Usage() in the 
if block.

Original issue reported on code.google.com by dgryski on 27 Jan 2012 at 9:20

GoogleCodeExporter commented 9 years ago
This issue was closed by revision 13aae0edebd5.

Original comment by dgryski on 2 May 2012 at 8:00