]> Cypherpunks repositories - gostls13.git/commitdiff
add NUL when allocating strings, to make use
authorRuss Cox <rsc@golang.org>
Wed, 27 May 2009 00:39:25 +0000 (17:39 -0700)
committerRuss Cox <rsc@golang.org>
Wed, 27 May 2009 00:39:25 +0000 (17:39 -0700)
of getenv by low-level runtime easier.
fix 32-bit bug in gc (there are still more).

R=ken
OCL=29415
CL=29415

src/runtime/mgc0.c
src/runtime/string.c

index 9c4061f6ece731a9d8b38a636548d5eeb1640af0..d58d6ce44d14027fae4f58663e3fa62acd09f006 100644 (file)
@@ -22,6 +22,10 @@ enum {
 extern byte etext[];
 extern byte end[];
 
+enum {
+       PtrSize = sizeof(void*)
+};
+
 static void
 scanblock(int32 depth, byte *b, int64 n)
 {
@@ -34,14 +38,14 @@ scanblock(int32 depth, byte *b, int64 n)
 
        if(Debug)
                printf("%d scanblock %p %D\n", depth, b, n);
-       off = (uint32)(uintptr)b & 7;
+       off = (uint32)(uintptr)b & (PtrSize-1);
        if(off) {
-               b += 8 - off;
-               n -= 8 - off;
+               b += PtrSize - off;
+               n -= PtrSize - off;
        }
 
        vp = (void**)b;
-       n /= 8;
+       n /= PtrSize;
        for(i=0; i<n; i++) {
                if(mlookup(vp[i], &obj, &size, &ref)) {
                        if(*ref == RefFree || *ref == RefStack)
index 5e4922a99f69464d235ee2539889bf9d4ad1c819..d7393ef6ed3b11929c0af1b7e73b29256799c4ce 100644 (file)
@@ -27,7 +27,7 @@ gostringsize(int32 l)
 
        if(l == 0)
                return emptystring;
-       s.str = mal(l);
+       s.str = mal(l+1);       // leave room for NUL for C runtime (e.g., callers of getenv)
        s.len = l;
        if(l > maxstring)
                maxstring = l;