Skip to content

runtime: find uses of int32 that should be uintptr #6046

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

Closed
bradfitz opened this issue Aug 5, 2013 · 16 comments
Closed

runtime: find uses of int32 that should be uintptr #6046

bradfitz opened this issue Aug 5, 2013 · 16 comments

Comments

@bradfitz
Copy link
Contributor

bradfitz commented Aug 5, 2013

In src/pkg/runtime/strings.goc, findnull uses an int32:

int32
runtime·findnull(byte *s)
{
        int32 l;

        if(s == nil)
                return 0;
        for(l=0; s[l]!=0; l++)
                ;
        return l;
}

And that is called by:

String
runtime·gostring(byte *str)
{
        intgo l;
        String s;

        l = runtime·findnull(str);
    s = gostringsize(l);
        runtime·memmove(s.str, str, l);
        return s;
}

Which means:

package main

/*
*/
import "C"
import "unsafe"

func main() {
    println("pre-make")
    buf := make([]byte, 1<<31 + 2)
    println("pre-set")
    for i := range buf {
        buf[i] = 'a'
    }
    buf[len(buf)-1] = 0
    println("pre-gostring")
    println(len(C.GoString((*C.char)(unsafe.Pointer(&buf[0])))))
}


$ go run x.go
pre-make
pre-set
pre-gostring
unexpected fault address 0xc190022000
fatal error: fault
[signal 0xa code=0x2 addr=0xc190022000 pc=0x401b7de]

goroutine 1 [running]:
runtime.throw(0x405e0dc)
    /Users/bradfitz/go/src/pkg/runtime/panic.c:498 +0x69 fp=0x4210e80
runtime.sigpanic()
    /Users/bradfitz/go/src/pkg/runtime/os_darwin.c:446 +0x1ed fp=0x4210e98
runtime.findnull(0xc210022000)
    /Users/bradfitz/go/src/pkg/runtime/string.goc:21 +0x1e fp=0x4210ea8
runtime.gostring(0x4210f00, 0xc210022000)
    /Users/bradfitz/go/src/pkg/runtime/string.goc:66 +0x27 fp=0x4210ee0
main._Cfunc_GoString(0xc210022000, 0xc, 0x80000002)
    command-line-arguments/_obj/_cgo_defun.c:10 +0x31 fp=0x4210ef8
main.main()
    /Users/bradfitz/x.go:19 +0x115 fp=0x4210f48
runtime.main()
    /Users/bradfitz/go/src/pkg/runtime/proc.c:201 +0x113 fp=0x4210fa0
runtime.goexit()
    /Users/bradfitz/go/src/pkg/runtime/proc.c:1333 fp=0x4210fa8
exit status 2
@ianlancetaylor
Copy link
Member

Comment 1:

See also findnullw, maxstring, the ms variable in gostringsize.  runtime·concatstring
looks pretty dubious too, it looks like the compiler calls it with an intgo, not an
int32.

@rsc
Copy link
Contributor

rsc commented Aug 5, 2013

Comment 2:

Re concatstring, I'm not too worried about people concatenating 2 billion
strings in a single addition expression.

@ianlancetaylor
Copy link
Member

Comment 3:

> Re concatstring, I'm not too worried about people concatenating 2 billion
> strings in a single addition expression.
No, of course not, but unless I'm mistaken the current code will fail strangely on a
64-bit big-endian system.

@rsc
Copy link
Contributor

rsc commented Aug 5, 2013

Comment 4:

Yes, that is true. That's probably not the only one either.

@robpike
Copy link
Contributor

robpike commented Aug 6, 2013

Comment 5:

I will never figure out how "Update issue xxx" works, because it never does.
findnull and findnullw: https://golang.org/cl/12520043
maxstring and concatstring: https://golang.org/cl/12519044

@robpike
Copy link
Contributor

robpike commented Aug 6, 2013

Comment 6:

On the topic of this general awfulness, would it be possible to change 6c et al. to
complain about integer operations mixing different signs and/or types? There's a gcc
flag for that that we're slowly turning on but there's no way at the moment to do it in
the runtime's C code. Since our C compiler is used only there, let's be strict.

@robpike
Copy link
Contributor

robpike commented Aug 6, 2013

Comment 7:

The CLs listed above are checked in. Leaving the bug open in case other things arise,
and changing the schedule to Go1.2

Labels changed: added go1.2, removed go1.2maybe.

@rsc
Copy link
Contributor

rsc commented Aug 6, 2013

Comment 8:

For "update issue xxx" you must not include the trailing period. Really.

@dvyukov
Copy link
Member

dvyukov commented Aug 10, 2013

Comment 9:

Owner changed to @robpike.

Status changed to Started.

@bradfitz
Copy link
Contributor Author

bradfitz commented Sep 3, 2013

Comment 10:

Status on this?  Should we open a separate bug for tracking changing cmd/cc to complain
about mixing integers?

@robpike
Copy link
Contributor

robpike commented Sep 3, 2013

Comment 11:

Close it if you think it's done.

@rsc
Copy link
Contributor

rsc commented Sep 5, 2013

Comment 12:

Labels changed: added go1.3maybe, removed go1.2.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 13:

Labels changed: added release-none, removed go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 14:

Labels changed: added repo-main.

@rsc rsc added this to the Unplanned milestone Apr 10, 2015
@robpike
Copy link
Contributor

robpike commented Sep 10, 2015

I suspect this is obsolete..

@bradfitz
Copy link
Contributor Author

Yes, I just verified they've been fixed.

@golang golang locked and limited conversation to collaborators Sep 22, 2016
@rsc rsc unassigned robpike Jun 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants