> So is my analysis correct?

I don't think so, but you've hidden the important parts of the backtrace 
which would show exactly where the error is.  Try trimming your program 
down to the *minimum* which reproduces the problem, then post the *entire* 
reproducer so we can run it and see the problem for ourselves.

> I am using go1.18

Go 1.18 support ended 2 years and 4 months ago, according 
to https://endoflife.date/go

On Friday, 6 June 2025 at 11:30:49 UTC+1 Zhaoxun Yan wrote:

> --------------------
> panic: runtime error: invalid memory address or nil pointer dereference
> [signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x6646f2]
>
> goroutine 1 [running]:
> util.CommandArgs({0xc000093cb0?, 0x2?, 0xc000071380?})
>         /home/zxun/src/util/util.go:49 +0xf2
> --------------------
> This error occurred because package [main] uses a function called 
> "CommandArgs" from my self-built package [util] with args in another 
> package [conf] in the same directory. Package [util] got lost because it 
> does not know where is package [conf]
> like this
> [util] /home/zxun/src/util.go
> [conf] /home/zxun/src/conf.go
> [main] /home/zxun/src/main.go...
> /home/zxun/src/go.mod:
>
> require(
>   util v0.0.0
>   ...
> replace util => ../util
>
> The usage line in main.go:
> fmt.Println( util.CommandArgs([]string{conf.IreportExec, 
> conf.IreportScript, "redis"}) )
>
> util.CommandArgs:
>
> func CommandArgs(args []string) string{
>   if len(args) ==0{
>     return "args are empty!"
>   }
>   var s string
>   if len(args) ==1{
>     out, er := exec.Command(args[0]).CombinedOutput()
>     s = er.Error()+string(out)
>   }else{
>     out, er := exec.Command(args[0],args[1:]...).CombinedOutput()
>     s = er.Error()+string(out)
>     fmt.Println(s)
>   }
>   return s
> }
>
> So is my analysis correct? I have not seen s printed yet, because s shall 
> include "<nil>" at the beginning. I am using go1.18. If the cause is util 
> package cannot access a variable in conf, is it possible to walk around by 
> a deepcopy of the string array (which will be in package main)?
>
> Thanks in advance.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/golang-nuts/73fe858a-e520-4580-94d3-cc2739eab076n%40googlegroups.com.

Reply via email to