diff options
| -rw-r--r-- | sys/src/games/mines/ghost.c | 6 | ||||
| -rw-r--r-- | sys/src/libmp/port/mpdiv.c | 4 | ||||
| -rw-r--r-- | sys/src/libplumb/mesg.c | 29 |
3 files changed, 28 insertions, 11 deletions
diff --git a/sys/src/games/mines/ghost.c b/sys/src/games/mines/ghost.c index 7f6375733..2dc36af4f 100644 --- a/sys/src/games/mines/ghost.c +++ b/sys/src/games/mines/ghost.c @@ -182,8 +182,8 @@ splitknown(CList **clp, int *nclp, int i, int *lastq) cl[ncl - 1 + j].mines = cl[i].pts == cl[i].mines; cl[ncl - 1 + j].pts = 1; cl[ncl - 1 + j].pt[0] = cl[i].pt[j]; - cl[*lastq].next = i; - *lastq = i; + cl[*lastq].next = ncl - 1 + j; + *lastq = ncl - 1 + j; } cl[i].mines = cl[i].pts == cl[i].mines; *nclp += cl[i].pts - 1; @@ -255,7 +255,7 @@ merge(CList **clp, int *nclp, int start, int split) next: ; } qi = q->next; - q->next = -1; + q->next = -2; } if(zero != 0){ for(i = 0, j = 0; i < *nclp; i++) diff --git a/sys/src/libmp/port/mpdiv.c b/sys/src/libmp/port/mpdiv.c index ea68acb43..cfd673cfa 100644 --- a/sys/src/libmp/port/mpdiv.c +++ b/sys/src/libmp/port/mpdiv.c @@ -22,7 +22,9 @@ mpdiv(mpint *dividend, mpint *divisor, mpint *quotient, mpint *remainder) // division by one or small powers of two if(divisor->top == 1 && (divisor->p[0] & divisor->p[0]-1) == 0){ - vlong r = (vlong)dividend->sign * (dividend->p[0] & divisor->p[0]-1); + vlong r = 0; + if(dividend->top > 0) + r = (vlong)dividend->sign * (dividend->p[0] & divisor->p[0]-1); if(quotient != nil){ sign = divisor->sign; for(s = 0; ((divisor->p[0] >> s) & 1) == 0; s++) diff --git a/sys/src/libplumb/mesg.c b/sys/src/libplumb/mesg.c index 328604288..e8aa2b5ad 100644 --- a/sys/src/libplumb/mesg.c +++ b/sys/src/libplumb/mesg.c @@ -76,21 +76,29 @@ quote(char *s, char *buf, char *bufe) char* plumbpackattr(Plumbattr *attr) { - int n; + int n, l; Plumbattr *a; char *s, *t, *buf, *bufe; if(attr == nil) return nil; - if((buf = malloc(4096)) == nil) + n = 0; + for(a=attr; a!=nil; a=a->next){ + l = Strlen(a->value); + if(l > n) + n = l; + } + if((buf = malloc(n*2+3)) == nil) return nil; - bufe = buf + 4096; + bufe = buf + n*2+3; n = 0; for(a=attr; a!=nil; a=a->next) n += Strlen(a->name) + 1 + Strlen(quote(a->value, buf, bufe)) + 1; s = malloc(n); - if(s == nil) + if(s == nil){ + free(buf); return nil; + } t = s; *t = '\0'; for(a=attr; a!=nil; a=a->next){ @@ -221,9 +229,11 @@ plumbunpackattr(char *p) char *q, *v, *buf, *bufe; int c, quoting; - if((buf = malloc(4096)) == nil) + c = strlen(p) + 1; + + if((buf = malloc(c)) == nil) return nil; - bufe = buf + 4096; + bufe = buf + c; attr = prev = nil; while(*p!='\0' && *p!='\n'){ while(*p==' ' || *p=='\t') @@ -340,6 +350,7 @@ plumbunpackpartial(char *buf, int n, int *morep) m = malloc(sizeof(Plumbmsg)); if(m == nil) return nil; + setmalloctag(m, getcallerpc(&buf)); memset(m, 0, sizeof(Plumbmsg)); if(morep != nil) *morep = 0; @@ -384,7 +395,11 @@ plumbunpackpartial(char *buf, int n, int *morep) Plumbmsg* plumbunpack(char *buf, int n) { - return plumbunpackpartial(buf, n, nil); + Plumbmsg *m; + m = plumbunpackpartial(buf, n, nil); + if(m != nil) + setmalloctag(m, getcallerpc(&buf)); + return m; } Plumbmsg* |
