This commit is contained in:
cinap_lenrek 2018-05-03 12:28:41 +02:00
commit 2cfc72db76
3 changed files with 28 additions and 11 deletions

View file

@ -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++)

View file

@ -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++)

View file

@ -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*