Commit 1a0a6f9d authored by Russ Cox's avatar Russ Cox

add NUL when allocating strings, to make use

of getenv by low-level runtime easier.
fix 32-bit bug in gc (there are still more).

R=ken
OCL=29415
CL=29415
parent 7d730755
...@@ -22,6 +22,10 @@ enum { ...@@ -22,6 +22,10 @@ enum {
extern byte etext[]; extern byte etext[];
extern byte end[]; extern byte end[];
enum {
PtrSize = sizeof(void*)
};
static void static void
scanblock(int32 depth, byte *b, int64 n) scanblock(int32 depth, byte *b, int64 n)
{ {
...@@ -34,14 +38,14 @@ scanblock(int32 depth, byte *b, int64 n) ...@@ -34,14 +38,14 @@ scanblock(int32 depth, byte *b, int64 n)
if(Debug) if(Debug)
printf("%d scanblock %p %D\n", depth, b, n); printf("%d scanblock %p %D\n", depth, b, n);
off = (uint32)(uintptr)b & 7; off = (uint32)(uintptr)b & (PtrSize-1);
if(off) { if(off) {
b += 8 - off; b += PtrSize - off;
n -= 8 - off; n -= PtrSize - off;
} }
vp = (void**)b; vp = (void**)b;
n /= 8; n /= PtrSize;
for(i=0; i<n; i++) { for(i=0; i<n; i++) {
if(mlookup(vp[i], &obj, &size, &ref)) { if(mlookup(vp[i], &obj, &size, &ref)) {
if(*ref == RefFree || *ref == RefStack) if(*ref == RefFree || *ref == RefStack)
......
...@@ -27,7 +27,7 @@ gostringsize(int32 l) ...@@ -27,7 +27,7 @@ gostringsize(int32 l)
if(l == 0) if(l == 0)
return emptystring; 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; s.len = l;
if(l > maxstring) if(l > maxstring)
maxstring = l; maxstring = l;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment