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
strings: Replace return wrong result on some machines #21585
Comments
@galric thank you for your detailed report. Can you please include a runnable example, perhaps from the Go playground, that shows the issue. Thank you. |
complete code: package main
import (
"flag"
"fmt"
"path/filepath"
"strings"
)
func main() {
downloadDir := flag.String("p", "", "")
flag.Parse()
fmt.Printf("downloadDir1: %s\n", *downloadDir)
dir := strings.TrimRight(*downloadDir, "/")
fmt.Printf("downloadDir2: %s\n", dir)
dir = filepath.Dir(dir)
fmt.Printf("dir: %s\n", dir)
fmt.Printf("replace: %s\n", strings.Replace(dir, "/cloud/app", "/cloud/data", 1))
} This problem happened on an physical machine in a intranet, and difficult to tell which system env has responsibility to it . It is really difficult for you to check this problem. most of machines are good can you list infos wanted |
This works as expected: https://play.golang.org/p/oeV3Bl17iy Without a reliable way to reproduce the issue, it's going to be near impossible to figure out what the issue is or if there even is one in the standard library. |
yes, it only appears in some machines not all, and I do understand it is difficult to debug a problem unable to reproduce. it seems I should learn 'how this assembly language works in runtime/asm_amd64.s' to debug this problem. |
In that case, try to rule out as many causes as you can. Have you tried 1.9rc2? What is the |
Have you tried building your program with the -race flag.
… On 24 Aug 2017, at 21:34, Daniel Martí ***@***.***> wrote:
In that case, try to rule out as many causes as you can. Have you tried 1.9rc2? What is the go env for the machine this happens on? Does it happen in multiple machines, or just that one?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
@mvdan I build binary on one machine and run it on others, only one machine has this problem. Shall I install go on this machine to see go env? with the code below and try many times, i found this problem disappear if the origin string is short binary build with this cmd also reproduce this problem @davecheney
code: package main
import (
"flag"
"fmt"
"strings"
)
func main() {
fullString := flag.String("f", "", "")
oldSub := flag.String("o", "", "")
newSub := flag.String("n", "", "")
flag.Parse()
fmt.Printf("FullString: %s\n", *fullString)
fmt.Printf("OldSub: %s\n", *oldSub)
fmt.Printf("NewSub: %s\n", *newSub)
fmt.Printf("replace: %s\n", strings.Replace(*fullString, *oldSub, *newSub, 1))
} go env on the build machine
|
Could you execute |
gdb message of reproduce problem
gdb message of not reproduce message
diff
|
This is really strange. All inputs to PCMPESTRI (xmm1,memory,rax,rdx,rdi) are the same, yet result is different. Just to rule out crazy idea, can you use |
I find the issue only appear on cpu9 of this machine, using this blew code.
I tried many times, and all results were the same
Other cpus are good. Dose any other c(c++) function also use this 'PCMPESTRI', so that i can prove it is the matter of cpu9? I tried 'string.find' and it works well on this cpu |
I used strings.Replace in my application to replace prefix '/cloud/app' with '/cloud/data', and got wrong result sometime.
expect: "/cloud/data/abc/abc/abc/123"
actual: some times "/cloud/app/abc/abc/abc/123" , some times "/cloud/data/abc/abc/abc/123"
Debuged 'strings.Replace' with gdb i found strings.indexShortStr return bad result, which is written with assembly language and i am not able to debug it.
summary of gdb message
full gdb message
What version of Go are you using (
go version
)?go1.8
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?gcc version 4.1.2 20080704 (Red Hat 4.1.2-50)
cpu
model name : Intel(R) Xeon(R) CPU E5-2650 v2 @ 2.60GHz
address sizes : 46 bits physical, 48 bits virtual
What did you do?
call: strings.Replace("/cloud/app/abc/abc/abc/123", "/cloud/app", "/cloud/data", 1)
What did you expect to see?
"/cloud/data/abc/abc/abc/123"
What did you see instead?
some times "/cloud/app/abc/abc/abc/123" , some times "/cloud/data/abc/abc/abc/123"
The text was updated successfully, but these errors were encountered: