diff options
| author | Russ Cox <rsc@golang.org> | 2011-11-03 12:44:51 -0400 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2011-11-03 12:44:51 -0400 |
| commit | 80bce97e45d99e7784bfa1d7d3563126d8c233e8 (patch) | |
| tree | 9b286946ffeb99dbb1a97d158cdaeb5c4d5cb8dd /src/cmd/ld/lib.c | |
| parent | d6ff3c11774bf36c797dcc6cd946819959766dc1 (diff) | |
| download | go-80bce97e45d99e7784bfa1d7d3563126d8c233e8.tar.xz | |
gc, ld: sync pathtoprefix + add comments
R=lvd, lvd
CC=golang-dev
https://golang.org/cl/5332051
Diffstat (limited to 'src/cmd/ld/lib.c')
| -rw-r--r-- | src/cmd/ld/lib.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/cmd/ld/lib.c b/src/cmd/ld/lib.c index 33fa0d1546..82f3f007f4 100644 --- a/src/cmd/ld/lib.c +++ b/src/cmd/ld/lib.c @@ -903,18 +903,26 @@ unmal(void *v, uint32 n) * Convert raw string to the prefix that will be used in the symbol table. * Invalid bytes turn into %xx. Right now the only bytes that need * escaping are %, ., and ", but we escape all control characters too. + * + * Must be same as ../gc/subr.c:/^pathtoprefix. */ static char* pathtoprefix(char *s) { static char hex[] = "0123456789abcdef"; - char *p, *r, *w; + char *p, *r, *w, *l; int n; + // find first character past the last slash, if any. + l = s; + for(r=s; *r; r++) + if(*r == '/') + l = r+1; + // check for chars that need escaping n = 0; for(r=s; *r; r++) - if(*r <= ' ' || *r == '.' || *r == '%' || *r == '"') + if(*r <= ' ' || (*r == '.' && r >= l) || *r == '%' || *r == '"' || *r >= 0x7f) n++; // quick exit @@ -924,7 +932,7 @@ pathtoprefix(char *s) // escape p = mal((r-s)+1+2*n); for(r=s, w=p; *r; r++) { - if(*r <= ' ' || *r == '.' || *r == '%' || *r == '"') { + if(*r <= ' ' || (*r == '.' && r >= l) || *r == '%' || *r == '"' || *r >= 0x7f) { *w++ = '%'; *w++ = hex[(*r>>4)&0xF]; *w++ = hex[*r&0xF]; |
