From e87ca8d97689ad9a63c0b56d0bfbda00c56abca2 Mon Sep 17 00:00:00 2001 From: aiju Date: Thu, 26 Apr 2018 14:55:02 +0100 Subject: [PATCH 1/5] mpdiv: fix dividing 0 by a small power of two --- sys/src/libmp/port/mpdiv.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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++) From d05b90f300b79b79eb8462aed9f649d76e432b78 Mon Sep 17 00:00:00 2001 From: mischief Date: Tue, 1 May 2018 12:47:26 -0700 Subject: [PATCH 2/5] libplumb: allow attributes larger than 4096, set some malloc tags --- sys/src/libplumb/mesg.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/sys/src/libplumb/mesg.c b/sys/src/libplumb/mesg.c index 328604288..5b111f679 100644 --- a/sys/src/libplumb/mesg.c +++ b/sys/src/libplumb/mesg.c @@ -76,15 +76,21 @@ 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; @@ -221,9 +227,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 +348,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 +393,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* From 28c519295f3cf6768f46f715c9a38e1739b8e966 Mon Sep 17 00:00:00 2001 From: aiju Date: Wed, 2 May 2018 22:47:04 +0000 Subject: [PATCH 3/5] games/mines -g: elements taken from list should be -2, not -1 --- sys/src/games/mines/ghost.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/src/games/mines/ghost.c b/sys/src/games/mines/ghost.c index 7f6375733..0c24d2ba0 100644 --- a/sys/src/games/mines/ghost.c +++ b/sys/src/games/mines/ghost.c @@ -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++) From 02e584c06c507a7802ed160ff954fa9fd080265c Mon Sep 17 00:00:00 2001 From: aiju Date: Wed, 2 May 2018 23:01:39 +0000 Subject: [PATCH 4/5] games/mines: chain new CLists in splitknown correctly --- sys/src/games/mines/ghost.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/src/games/mines/ghost.c b/sys/src/games/mines/ghost.c index 0c24d2ba0..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; From 12716019bfdc3bedda1c8489d87a7cd316d016ef Mon Sep 17 00:00:00 2001 From: mischief Date: Thu, 3 May 2018 01:26:09 -0700 Subject: [PATCH 5/5] libplumb: fix old leak introduced in 18b8ed1a5ea3 --- sys/src/libplumb/mesg.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sys/src/libplumb/mesg.c b/sys/src/libplumb/mesg.c index 5b111f679..e8aa2b5ad 100644 --- a/sys/src/libplumb/mesg.c +++ b/sys/src/libplumb/mesg.c @@ -95,8 +95,10 @@ plumbpackattr(Plumbattr *attr) 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){