Commit 7590e28d authored by Ian Lance Taylor's avatar Ian Lance Taylor

lib9: avoid all -Wconversion warnings

Built after adding -Wconversion to the list of compiler
arguments used when building.  I believe these are all OK
assuming we will not change the API.  There is no effort to
detect overflow due to very long strings.

R=golang-dev, dave, rsc, r
CC=golang-dev
https://golang.org/cl/10195044
parent 07cb48c3
...@@ -68,12 +68,12 @@ _p9dir(struct stat *lst, struct stat *st, char *name, Dir *d, char **str, char * ...@@ -68,12 +68,12 @@ _p9dir(struct stat *lst, struct stat *st, char *name, Dir *d, char **str, char *
*str += strlen(*str)+1; *str += strlen(*str)+1;
} }
} }
sz += strlen(s)+1; sz += (int)strlen(s)+1;
/* user */ /* user */
snprint(tmp, sizeof tmp, "%d", (int)st->st_uid); snprint(tmp, sizeof tmp, "%d", (int)st->st_uid);
s = tmp; s = tmp;
sz += strlen(s)+1; sz += (int)strlen(s)+1;
if(d){ if(d){
if(*str+strlen(s)+1 > estr) if(*str+strlen(s)+1 > estr)
d->uid = "oops"; d->uid = "oops";
...@@ -87,7 +87,7 @@ _p9dir(struct stat *lst, struct stat *st, char *name, Dir *d, char **str, char * ...@@ -87,7 +87,7 @@ _p9dir(struct stat *lst, struct stat *st, char *name, Dir *d, char **str, char *
/* group */ /* group */
snprint(tmp, sizeof tmp, "%d", (int)st->st_gid); snprint(tmp, sizeof tmp, "%d", (int)st->st_gid);
s = tmp; s = tmp;
sz += strlen(s)+1; sz += (int)strlen(s)+1;
if(d){ if(d){
if(*str + strlen(s)+1 > estr) if(*str + strlen(s)+1 > estr)
d->gid = "oops"; d->gid = "oops";
...@@ -107,10 +107,10 @@ _p9dir(struct stat *lst, struct stat *st, char *name, Dir *d, char **str, char * ...@@ -107,10 +107,10 @@ _p9dir(struct stat *lst, struct stat *st, char *name, Dir *d, char **str, char *
d->qid.vers = st->st_gen; d->qid.vers = st->st_gen;
#endif #endif
if(d->qid.vers == 0) if(d->qid.vers == 0)
d->qid.vers = st->st_mtime + st->st_ctime; d->qid.vers = (ulong)(st->st_mtime + st->st_ctime);
d->mode = st->st_mode&0777; d->mode = st->st_mode&0777;
d->atime = st->st_atime; d->atime = (ulong)st->st_atime;
d->mtime = st->st_mtime; d->mtime = (ulong)st->st_mtime;
d->length = st->st_size; d->length = st->st_size;
if(S_ISDIR(st->st_mode)){ if(S_ISDIR(st->st_mode)){
......
...@@ -29,7 +29,7 @@ THE SOFTWARE. ...@@ -29,7 +29,7 @@ THE SOFTWARE.
int int
atoi(char *s) atoi(char *s)
{ {
return strtol(s, 0, 0); return (int)strtol(s, 0, 0);
} }
long long
......
...@@ -134,8 +134,8 @@ _wait(int pid4, int opt) ...@@ -134,8 +134,8 @@ _wait(int pid4, int opt)
free(w); free(w);
return nil; return nil;
} }
u = ru.ru_utime.tv_sec*1000+((ru.ru_utime.tv_usec+500)/1000); u = (ulong)(ru.ru_utime.tv_sec*1000+((ru.ru_utime.tv_usec+500)/1000));
s = ru.ru_stime.tv_sec*1000+((ru.ru_stime.tv_usec+500)/1000); s = (ulong)(ru.ru_stime.tv_sec*1000+((ru.ru_stime.tv_usec+500)/1000));
w->pid = pid; w->pid = pid;
w->time[0] = u; w->time[0] = u;
w->time[1] = s; w->time[1] = s;
......
...@@ -43,10 +43,10 @@ dirfstat(int fd) ...@@ -43,10 +43,10 @@ dirfstat(int fd)
snprint(tmp, sizeof tmp, "/dev/fd/%d", fd); snprint(tmp, sizeof tmp, "/dev/fd/%d", fd);
nstr = _p9dir(&st, &st, tmp, nil, nil, nil); nstr = _p9dir(&st, &st, tmp, nil, nil, nil);
d = malloc(sizeof(Dir)+nstr); d = malloc(sizeof(Dir)+(size_t)nstr);
if(d == nil) if(d == nil)
return nil; return nil;
memset(d, 0, sizeof(Dir)+nstr); memset(d, 0, sizeof(Dir)+(size_t)nstr);
str = (char*)&d[1]; str = (char*)&d[1];
_p9dir(&st, &st, tmp, d, &str, str+nstr); _p9dir(&st, &st, tmp, d, &str, str+nstr);
return d; return d;
......
...@@ -63,14 +63,14 @@ dirfwstat(int fd, Dir *dir) ...@@ -63,14 +63,14 @@ dirfwstat(int fd, Dir *dir)
ret = 0; ret = 0;
#ifndef _WIN32 #ifndef _WIN32
if(~dir->mode != 0){ if(~dir->mode != 0){
if(fchmod(fd, dir->mode) < 0) if(fchmod(fd, (mode_t)dir->mode) < 0)
ret = -1; ret = -1;
} }
#endif #endif
if(~dir->mtime != 0){ if(~dir->mtime != 0){
tv[0].tv_sec = dir->mtime; tv[0].tv_sec = (time_t)dir->mtime;
tv[0].tv_usec = 0; tv[0].tv_usec = 0;
tv[1].tv_sec = dir->mtime; tv[1].tv_sec = (time_t)dir->mtime;
tv[1].tv_usec = 0; tv[1].tv_usec = 0;
if(futimes(fd, tv) < 0) if(futimes(fd, tv) < 0)
ret = -1; ret = -1;
......
...@@ -52,10 +52,10 @@ dirstat(char *file) ...@@ -52,10 +52,10 @@ dirstat(char *file)
#endif #endif
nstr = _p9dir(&lst, &st, file, nil, nil, nil); nstr = _p9dir(&lst, &st, file, nil, nil, nil);
d = malloc(sizeof(Dir)+nstr); d = malloc(sizeof(Dir)+(size_t)nstr);
if(d == nil) if(d == nil)
return nil; return nil;
memset(d, 0, sizeof(Dir)+nstr); memset(d, 0, sizeof(Dir)+(size_t)nstr);
str = (char*)&d[1]; str = (char*)&d[1];
_p9dir(&lst, &st, file, d, &str, str+nstr); _p9dir(&lst, &st, file, d, &str, str+nstr);
return d; return d;
......
...@@ -37,7 +37,7 @@ dirwstat(char *file, Dir *dir) ...@@ -37,7 +37,7 @@ dirwstat(char *file, Dir *dir)
if(~dir->mtime == 0) if(~dir->mtime == 0)
return 0; return 0;
ub.actime = dir->mtime; ub.actime = (time_t)dir->mtime;
ub.modtime = dir->mtime; ub.modtime = (time_t)dir->mtime;
return utime(file, &ub); return utime(file, &ub);
} }
...@@ -37,7 +37,7 @@ execl(char *prog, ...) ...@@ -37,7 +37,7 @@ execl(char *prog, ...)
; ;
va_end(arg); va_end(arg);
argv = malloc((i+1)*sizeof(char*)); argv = malloc((size_t)(i+1)*sizeof(char*));
if(argv == nil) if(argv == nil)
return -1; return -1;
......
...@@ -54,7 +54,7 @@ lookflag(char *name, int namelen, int creat) ...@@ -54,7 +54,7 @@ lookflag(char *name, int namelen, int creat)
h = fnv(name, namelen) & (nelem(fhash)-1); h = fnv(name, namelen) & (nelem(fhash)-1);
for(f=fhash[h]; f; f=f->next) { for(f=fhash[h]; f; f=f->next) {
if(f->namelen == namelen && memcmp(f->name, name, namelen) == 0) { if(f->namelen == namelen && memcmp(f->name, name, (size_t)namelen) == 0) {
if(creat) if(creat)
sysfatal("multiple definitions of flag -%s", name); sysfatal("multiple definitions of flag -%s", name);
return f; return f;
...@@ -97,7 +97,7 @@ flagcount(char *name, char *desc, int *p) ...@@ -97,7 +97,7 @@ flagcount(char *name, char *desc, int *p)
{ {
Flag *f; Flag *f;
f = lookflag(name, strlen(name), 1); f = lookflag(name, (int)strlen(name), 1);
f->desc = desc; f->desc = desc;
f->iscount = 1; f->iscount = 1;
f->set = count; f->set = count;
...@@ -119,7 +119,7 @@ flagint64(char *name, char *desc, int64 *p) ...@@ -119,7 +119,7 @@ flagint64(char *name, char *desc, int64 *p)
{ {
Flag *f; Flag *f;
f = lookflag(name, strlen(name), 1); f = lookflag(name, (int)strlen(name), 1);
f->desc = desc; f->desc = desc;
f->set = atollwhex; f->set = atollwhex;
f->arg = p; f->arg = p;
...@@ -130,7 +130,7 @@ atolwhex(char *s, void *p) ...@@ -130,7 +130,7 @@ atolwhex(char *s, void *p)
{ {
char *t; char *t;
*(int32*)p = strtol(s, &t, 0); *(int32*)p = (int32)strtol(s, &t, 0);
if(*s == '\0' || *t != '\0') if(*s == '\0' || *t != '\0')
sysfatal("invalid numeric argument -%s=%s", curflag->name, s); sysfatal("invalid numeric argument -%s=%s", curflag->name, s);
} }
...@@ -140,7 +140,7 @@ flagint32(char *name, char *desc, int32 *p) ...@@ -140,7 +140,7 @@ flagint32(char *name, char *desc, int32 *p)
{ {
Flag *f; Flag *f;
f = lookflag(name, strlen(name), 1); f = lookflag(name, (int)strlen(name), 1);
f->desc = desc; f->desc = desc;
f->set = atolwhex; f->set = atolwhex;
f->arg = p; f->arg = p;
...@@ -158,7 +158,7 @@ flagstr(char *name, char *desc, char **p) ...@@ -158,7 +158,7 @@ flagstr(char *name, char *desc, char **p)
Flag *f; Flag *f;
f = lookflag(name, strlen(name), 1); f = lookflag(name, (int)strlen(name), 1);
f->desc = desc; f->desc = desc;
f->set = string; f->set = string;
f->arg = p; f->arg = p;
...@@ -176,7 +176,7 @@ flagfn0(char *name, char *desc, void (*fn)(void)) ...@@ -176,7 +176,7 @@ flagfn0(char *name, char *desc, void (*fn)(void))
{ {
Flag *f; Flag *f;
f = lookflag(name, strlen(name), 1); f = lookflag(name, (int)strlen(name), 1);
f->desc = desc; f->desc = desc;
f->set = fn0; f->set = fn0;
f->arg = fn; f->arg = fn;
...@@ -194,7 +194,7 @@ flagfn1(char *name, char *desc, void (*fn)(char*)) ...@@ -194,7 +194,7 @@ flagfn1(char *name, char *desc, void (*fn)(char*))
{ {
Flag *f; Flag *f;
f = lookflag(name, strlen(name), 1); f = lookflag(name, (int)strlen(name), 1);
f->desc = desc; f->desc = desc;
f->set = fn1; f->set = fn1;
f->arg = fn; f->arg = fn;
...@@ -211,7 +211,7 @@ flagfn2(char *name, char *desc, void (*fn)(char*, char*)) ...@@ -211,7 +211,7 @@ flagfn2(char *name, char *desc, void (*fn)(char*, char*))
{ {
Flag *f; Flag *f;
f = lookflag(name, strlen(name), 1); f = lookflag(name, (int)strlen(name), 1);
f->desc = desc; f->desc = desc;
f->set2 = fn2; f->set2 = fn2;
f->arg = fn; f->arg = fn;
...@@ -253,9 +253,9 @@ flagparse(int *argcp, char ***argvp, void (*usage)(void)) ...@@ -253,9 +253,9 @@ flagparse(int *argcp, char ***argvp, void (*usage)(void))
name = p+1; name = p+1;
q = strchr(name, '='); q = strchr(name, '=');
if(q != nil) if(q != nil)
namelen = q++ - name; namelen = (int)(q++ - name);
else else
namelen = strlen(name); namelen = (int)strlen(name);
f = lookflag(name, namelen, 0); f = lookflag(name, namelen, 0);
if(f == nil) { if(f == nil) {
if(strcmp(p, "-h") == 0 || strcmp(p, "-help") == 0 || strcmp(p, "-?") == 0) if(strcmp(p, "-h") == 0 || strcmp(p, "-help") == 0 || strcmp(p, "-?") == 0)
......
...@@ -25,7 +25,7 @@ int ...@@ -25,7 +25,7 @@ int
dofmt(Fmt *f, char *fmt) dofmt(Fmt *f, char *fmt)
{ {
Rune rune, *rt, *rs; Rune rune, *rt, *rs;
int r; Rune r;
char *t, *s; char *t, *s;
int n, nfmt; int n, nfmt;
...@@ -34,7 +34,7 @@ dofmt(Fmt *f, char *fmt) ...@@ -34,7 +34,7 @@ dofmt(Fmt *f, char *fmt)
if(f->runes){ if(f->runes){
rt = (Rune*)f->to; rt = (Rune*)f->to;
rs = (Rune*)f->stop; rs = (Rune*)f->stop;
while((r = *(uchar*)fmt) && r != '%'){ while((r = (Rune)*(uchar*)fmt) && r != '%'){
if(r < Runeself) if(r < Runeself)
fmt++; fmt++;
else{ else{
...@@ -44,7 +44,7 @@ dofmt(Fmt *f, char *fmt) ...@@ -44,7 +44,7 @@ dofmt(Fmt *f, char *fmt)
FMTRCHAR(f, rt, rs, r); FMTRCHAR(f, rt, rs, r);
} }
fmt++; fmt++;
f->nfmt += rt - (Rune *)f->to; f->nfmt += (int)(rt - (Rune *)f->to);
f->to = rt; f->to = rt;
if(!r) if(!r)
return f->nfmt - nfmt; return f->nfmt - nfmt;
...@@ -52,7 +52,7 @@ dofmt(Fmt *f, char *fmt) ...@@ -52,7 +52,7 @@ dofmt(Fmt *f, char *fmt)
}else{ }else{
t = (char*)f->to; t = (char*)f->to;
s = (char*)f->stop; s = (char*)f->stop;
while((r = *(uchar*)fmt) && r != '%'){ while((r = (Rune)*(uchar*)fmt) && r != '%'){
if(r < Runeself){ if(r < Runeself){
FMTCHAR(f, t, s, r); FMTCHAR(f, t, s, r);
fmt++; fmt++;
...@@ -70,7 +70,7 @@ dofmt(Fmt *f, char *fmt) ...@@ -70,7 +70,7 @@ dofmt(Fmt *f, char *fmt)
} }
} }
fmt++; fmt++;
f->nfmt += t - (char *)f->to; f->nfmt += (int)(t - (char *)f->to);
f->to = t; f->to = t;
if(!r) if(!r)
return f->nfmt - nfmt; return f->nfmt - nfmt;
...@@ -87,9 +87,9 @@ void * ...@@ -87,9 +87,9 @@ void *
__fmtflush(Fmt *f, void *t, int len) __fmtflush(Fmt *f, void *t, int len)
{ {
if(f->runes) if(f->runes)
f->nfmt += (Rune*)t - (Rune*)f->to; f->nfmt += (int)((Rune*)t - (Rune*)f->to);
else else
f->nfmt += (char*)t - (char *)f->to; f->nfmt += (int)((char*)t - (char *)f->to);
f->to = t; f->to = t;
if(f->flush == 0 || (*f->flush)(f) == 0 || (char*)f->to + len > (char*)f->stop){ if(f->flush == 0 || (*f->flush)(f) == 0 || (char*)f->to + len > (char*)f->stop){
f->stop = f->to; f->stop = f->to;
...@@ -112,7 +112,7 @@ __fmtpad(Fmt *f, int n) ...@@ -112,7 +112,7 @@ __fmtpad(Fmt *f, int n)
s = (char*)f->stop; s = (char*)f->stop;
for(i = 0; i < n; i++) for(i = 0; i < n; i++)
FMTCHAR(f, t, s, ' '); FMTCHAR(f, t, s, ' ');
f->nfmt += t - (char *)f->to; f->nfmt += (int)(t - (char *)f->to);
f->to = t; f->to = t;
return 0; return 0;
} }
...@@ -127,7 +127,7 @@ __rfmtpad(Fmt *f, int n) ...@@ -127,7 +127,7 @@ __rfmtpad(Fmt *f, int n)
s = (Rune*)f->stop; s = (Rune*)f->stop;
for(i = 0; i < n; i++) for(i = 0; i < n; i++)
FMTRCHAR(f, t, s, ' '); FMTRCHAR(f, t, s, ' ');
f->nfmt += t - (Rune *)f->to; f->nfmt += (int)(t - (Rune *)f->to);
f->to = t; f->to = t;
return 0; return 0;
} }
...@@ -157,13 +157,13 @@ __fmtcpy(Fmt *f, const void *vm, int n, int sz) ...@@ -157,13 +157,13 @@ __fmtcpy(Fmt *f, const void *vm, int n, int sz)
r = *(uchar*)m; r = *(uchar*)m;
if(r < Runeself) if(r < Runeself)
m++; m++;
else if((me - m) >= UTFmax || fullrune(m, me-m)) else if((me - m) >= UTFmax || fullrune(m, (int)(me-m)))
m += chartorune(&r, m); m += chartorune(&r, m);
else else
break; break;
FMTRCHAR(f, rt, rs, r); FMTRCHAR(f, rt, rs, r);
} }
f->nfmt += rt - (Rune *)f->to; f->nfmt += (int)(rt - (Rune *)f->to);
f->to = rt; f->to = rt;
if(fl & FmtLeft && __rfmtpad(f, w - n) < 0) if(fl & FmtLeft && __rfmtpad(f, w - n) < 0)
return -1; return -1;
...@@ -176,13 +176,13 @@ __fmtcpy(Fmt *f, const void *vm, int n, int sz) ...@@ -176,13 +176,13 @@ __fmtcpy(Fmt *f, const void *vm, int n, int sz)
r = *(uchar*)m; r = *(uchar*)m;
if(r < Runeself) if(r < Runeself)
m++; m++;
else if((me - m) >= UTFmax || fullrune(m, me-m)) else if((me - m) >= UTFmax || fullrune(m, (int)(me-m)))
m += chartorune(&r, m); m += chartorune(&r, m);
else else
break; break;
FMTRUNE(f, t, s, r); FMTRUNE(f, t, s, r);
} }
f->nfmt += t - (char *)f->to; f->nfmt += (int)(t - (char *)f->to);
f->to = t; f->to = t;
if(fl & FmtLeft && __fmtpad(f, w - n) < 0) if(fl & FmtLeft && __fmtpad(f, w - n) < 0)
return -1; return -1;
...@@ -212,7 +212,7 @@ __fmtrcpy(Fmt *f, const void *vm, int n) ...@@ -212,7 +212,7 @@ __fmtrcpy(Fmt *f, const void *vm, int n)
rs = (Rune*)f->stop; rs = (Rune*)f->stop;
for(me = m + n; m < me; m++) for(me = m + n; m < me; m++)
FMTRCHAR(f, rt, rs, *m); FMTRCHAR(f, rt, rs, *m);
f->nfmt += rt - (Rune *)f->to; f->nfmt += (int)(rt - (Rune *)f->to);
f->to = rt; f->to = rt;
if(fl & FmtLeft && __rfmtpad(f, w - n) < 0) if(fl & FmtLeft && __rfmtpad(f, w - n) < 0)
return -1; return -1;
...@@ -225,7 +225,7 @@ __fmtrcpy(Fmt *f, const void *vm, int n) ...@@ -225,7 +225,7 @@ __fmtrcpy(Fmt *f, const void *vm, int n)
r = *m; r = *m;
FMTRUNE(f, t, s, r); FMTRUNE(f, t, s, r);
} }
f->nfmt += t - (char *)f->to; f->nfmt += (int)(t - (char *)f->to);
f->to = t; f->to = t;
if(fl & FmtLeft && __fmtpad(f, w - n) < 0) if(fl & FmtLeft && __fmtpad(f, w - n) < 0)
return -1; return -1;
...@@ -239,7 +239,7 @@ __charfmt(Fmt *f) ...@@ -239,7 +239,7 @@ __charfmt(Fmt *f)
{ {
char x[1]; char x[1];
x[0] = va_arg(f->args, int); x[0] = (char)va_arg(f->args, int);
f->prec = 1; f->prec = 1;
return __fmtcpy(f, (const char*)x, 1, 1); return __fmtcpy(f, (const char*)x, 1, 1);
} }
...@@ -250,7 +250,7 @@ __runefmt(Fmt *f) ...@@ -250,7 +250,7 @@ __runefmt(Fmt *f)
{ {
Rune x[1]; Rune x[1];
x[0] = va_arg(f->args, int); x[0] = (Rune)va_arg(f->args, int);
return __fmtrcpy(f, (const void*)x, 1); return __fmtrcpy(f, (const void*)x, 1);
} }
...@@ -278,7 +278,7 @@ fmtstrcpy(Fmt *f, char *s) ...@@ -278,7 +278,7 @@ fmtstrcpy(Fmt *f, char *s)
#endif #endif
return __fmtcpy(f, s, j, i); return __fmtcpy(f, s, j, i);
} }
return __fmtcpy(f, s, utflen(s), strlen(s)); return __fmtcpy(f, s, utflen(s), (int)strlen(s));
} }
/* fmt out a null terminated utf string */ /* fmt out a null terminated utf string */
...@@ -309,7 +309,7 @@ fmtrunestrcpy(Fmt *f, Rune *s) ...@@ -309,7 +309,7 @@ fmtrunestrcpy(Fmt *f, Rune *s)
}else{ }else{
for(e = s; *e; e++) for(e = s; *e; e++)
; ;
n = e - s; n = (int)(e - s);
} }
return __fmtrcpy(f, s, n); return __fmtrcpy(f, s, n);
} }
...@@ -342,8 +342,8 @@ __ifmt(Fmt *f) ...@@ -342,8 +342,8 @@ __ifmt(Fmt *f)
char buf[140], *p, *conv; char buf[140], *p, *conv;
/* 140: for 64 bits of binary + 3-byte sep every 4 digits */ /* 140: for 64 bits of binary + 3-byte sep every 4 digits */
uvlong vu; uvlong vu;
ulong u; ulong fl, u;
int neg, base, i, n, fl, w, isv; int neg, base, i, n, w, isv;
int ndig, len, excess, bytelen; int ndig, len, excess, bytelen;
char *grouping; char *grouping;
char *thousands; char *thousands;
...@@ -377,27 +377,27 @@ __ifmt(Fmt *f) ...@@ -377,27 +377,27 @@ __ifmt(Fmt *f)
if(fl & FmtUnsigned) if(fl & FmtUnsigned)
vu = va_arg(f->args, uvlong); vu = va_arg(f->args, uvlong);
else else
vu = va_arg(f->args, vlong); vu = (uvlong)va_arg(f->args, vlong);
}else if(fl & FmtLong){ }else if(fl & FmtLong){
if(fl & FmtUnsigned) if(fl & FmtUnsigned)
u = va_arg(f->args, ulong); u = va_arg(f->args, ulong);
else else
u = va_arg(f->args, long); u = (ulong)va_arg(f->args, long);
}else if(fl & FmtByte){ }else if(fl & FmtByte){
if(fl & FmtUnsigned) if(fl & FmtUnsigned)
u = (uchar)va_arg(f->args, int); u = (uchar)va_arg(f->args, int);
else else
u = (char)va_arg(f->args, int); u = (uchar)(char)va_arg(f->args, int);
}else if(fl & FmtShort){ }else if(fl & FmtShort){
if(fl & FmtUnsigned) if(fl & FmtUnsigned)
u = (ushort)va_arg(f->args, int); u = (ushort)va_arg(f->args, int);
else else
u = (short)va_arg(f->args, int); u = (ushort)(short)va_arg(f->args, int);
}else{ }else{
if(fl & FmtUnsigned) if(fl & FmtUnsigned)
u = va_arg(f->args, uint); u = va_arg(f->args, uint);
else else
u = va_arg(f->args, int); u = (uint)va_arg(f->args, int);
} }
conv = "0123456789abcdef"; conv = "0123456789abcdef";
grouping = "\4"; /* for hex, octal etc. (undefined by spec but nice) */ grouping = "\4"; /* for hex, octal etc. (undefined by spec but nice) */
...@@ -428,10 +428,10 @@ __ifmt(Fmt *f) ...@@ -428,10 +428,10 @@ __ifmt(Fmt *f)
} }
if(!(fl & FmtUnsigned)){ if(!(fl & FmtUnsigned)){
if(isv && (vlong)vu < 0){ if(isv && (vlong)vu < 0){
vu = -(vlong)vu; vu = (uvlong)-(vlong)vu;
neg = 1; neg = 1;
}else if(!isv && (long)u < 0){ }else if(!isv && (long)u < 0){
u = -(long)u; u = (ulong)-(long)u;
neg = 1; neg = 1;
} }
} }
...@@ -440,11 +440,11 @@ __ifmt(Fmt *f) ...@@ -440,11 +440,11 @@ __ifmt(Fmt *f)
excess = 0; /* number of bytes > number runes */ excess = 0; /* number of bytes > number runes */
ndig = 0; ndig = 0;
len = utflen(thousands); len = utflen(thousands);
bytelen = strlen(thousands); bytelen = (int)strlen(thousands);
if(isv){ if(isv){
while(vu){ while(vu){
i = vu % base; i = (int)(vu % (uvlong)base);
vu /= base; vu /= (uvlong)base;
if((fl & FmtComma) && n % 4 == 3){ if((fl & FmtComma) && n % 4 == 3){
*p-- = ','; *p-- = ',';
n++; n++;
...@@ -453,15 +453,15 @@ __ifmt(Fmt *f) ...@@ -453,15 +453,15 @@ __ifmt(Fmt *f)
n += len; n += len;
excess += bytelen - len; excess += bytelen - len;
p -= bytelen; p -= bytelen;
memmove(p+1, thousands, bytelen); memmove(p+1, thousands, (size_t)bytelen);
} }
*p-- = conv[i]; *p-- = conv[i];
n++; n++;
} }
}else{ }else{
while(u){ while(u){
i = u % base; i = (int)(u % (ulong)base);
u /= base; u /= (ulong)base;
if((fl & FmtComma) && n % 4 == 3){ if((fl & FmtComma) && n % 4 == 3){
*p-- = ','; *p-- = ',';
n++; n++;
...@@ -470,7 +470,7 @@ __ifmt(Fmt *f) ...@@ -470,7 +470,7 @@ __ifmt(Fmt *f)
n += len; n += len;
excess += bytelen - len; excess += bytelen - len;
p -= bytelen; p -= bytelen;
memmove(p+1, thousands, bytelen); memmove(p+1, thousands, (size_t)bytelen);
} }
*p-- = conv[i]; *p-- = conv[i];
n++; n++;
...@@ -496,14 +496,14 @@ __ifmt(Fmt *f) ...@@ -496,14 +496,14 @@ __ifmt(Fmt *f)
* Zero values don't get 0x. * Zero values don't get 0x.
*/ */
if(f->r == 'x' || f->r == 'X') if(f->r == 'x' || f->r == 'X')
fl &= ~FmtSharp; fl &= ~(ulong)FmtSharp;
} }
for(w = f->prec; n < w && p > buf+3; n++){ for(w = f->prec; n < w && p > buf+3; n++){
if((fl & FmtApost) && __needsep(&ndig, &grouping)){ if((fl & FmtApost) && __needsep(&ndig, &grouping)){
n += len; n += len;
excess += bytelen - len; excess += bytelen - len;
p -= bytelen; p -= bytelen;
memmove(p+1, thousands, bytelen); memmove(p+1, thousands, (size_t)bytelen);
} }
*p-- = '0'; *p-- = '0';
} }
...@@ -514,7 +514,7 @@ __ifmt(Fmt *f) ...@@ -514,7 +514,7 @@ __ifmt(Fmt *f)
n += 2; n += 2;
else if(base == 8){ else if(base == 8){
if(p[1] == '0') if(p[1] == '0')
fl &= ~FmtSharp; fl &= ~(ulong)FmtSharp;
else else
n++; n++;
} }
...@@ -528,15 +528,15 @@ __ifmt(Fmt *f) ...@@ -528,15 +528,15 @@ __ifmt(Fmt *f)
n += len; n += len;
excess += bytelen - len; excess += bytelen - len;
p -= bytelen; p -= bytelen;
memmove(p+1, thousands, bytelen); memmove(p+1, thousands, (size_t)bytelen);
} }
*p-- = '0'; *p-- = '0';
} }
f->flags &= ~FmtWidth; f->flags &= ~(ulong)FmtWidth;
} }
if(fl & FmtSharp){ if(fl & FmtSharp){
if(base == 16) if(base == 16)
*p-- = f->r; *p-- = (char)f->r;
if(base == 16 || base == 8) if(base == 16 || base == 8)
*p-- = '0'; *p-- = '0';
} }
...@@ -546,7 +546,7 @@ __ifmt(Fmt *f) ...@@ -546,7 +546,7 @@ __ifmt(Fmt *f)
*p-- = '+'; *p-- = '+';
else if(fl & FmtSpace) else if(fl & FmtSpace)
*p-- = ' '; *p-- = ' ';
f->flags &= ~FmtPrec; f->flags &= ~(ulong)FmtPrec;
return __fmtcpy(f, p + 1, n, n + excess); return __fmtcpy(f, p + 1, n, n + excess);
} }
...@@ -563,9 +563,9 @@ __countfmt(Fmt *f) ...@@ -563,9 +563,9 @@ __countfmt(Fmt *f)
}else if(fl & FmtLong){ }else if(fl & FmtLong){
*(long*)p = f->nfmt; *(long*)p = f->nfmt;
}else if(fl & FmtByte){ }else if(fl & FmtByte){
*(char*)p = f->nfmt; *(char*)p = (char)f->nfmt;
}else if(fl & FmtShort){ }else if(fl & FmtShort){
*(short*)p = f->nfmt; *(short*)p = (short)f->nfmt;
}else{ }else{
*(int*)p = f->nfmt; *(int*)p = f->nfmt;
} }
......
...@@ -27,7 +27,7 @@ int ...@@ -27,7 +27,7 @@ int
dorfmt(Fmt *f, const Rune *fmt) dorfmt(Fmt *f, const Rune *fmt)
{ {
Rune *rt, *rs; Rune *rt, *rs;
int r; Rune r;
char *t, *s; char *t, *s;
int nfmt; int nfmt;
...@@ -39,7 +39,7 @@ dorfmt(Fmt *f, const Rune *fmt) ...@@ -39,7 +39,7 @@ dorfmt(Fmt *f, const Rune *fmt)
while((r = *fmt++) && r != '%'){ while((r = *fmt++) && r != '%'){
FMTRCHAR(f, rt, rs, r); FMTRCHAR(f, rt, rs, r);
} }
f->nfmt += rt - (Rune *)f->to; f->nfmt += (int)(rt - (Rune *)f->to);
f->to = rt; f->to = rt;
if(!r) if(!r)
return f->nfmt - nfmt; return f->nfmt - nfmt;
...@@ -50,7 +50,7 @@ dorfmt(Fmt *f, const Rune *fmt) ...@@ -50,7 +50,7 @@ dorfmt(Fmt *f, const Rune *fmt)
while((r = *fmt++) && r != '%'){ while((r = *fmt++) && r != '%'){
FMTRUNE(f, t, f->stop, r); FMTRUNE(f, t, f->stop, r);
} }
f->nfmt += t - (char *)f->to; f->nfmt += (int)(t - (char *)f->to);
f->to = t; f->to = t;
if(!r) if(!r)
return f->nfmt - nfmt; return f->nfmt - nfmt;
......
...@@ -103,7 +103,7 @@ xadd1(char *a, int n) ...@@ -103,7 +103,7 @@ xadd1(char *a, int n)
for(b = a+n-1; b >= a; b--) { for(b = a+n-1; b >= a; b--) {
c = *b + 1; c = *b + 1;
if(c <= '9') { if(c <= '9') {
*b = c; *b = (char)c;
return 0; return 0;
} }
*b = '0'; *b = '0';
...@@ -144,7 +144,7 @@ xsub1(char *a, int n) ...@@ -144,7 +144,7 @@ xsub1(char *a, int n)
*b = '9'; *b = '9';
return 1; return 1;
} }
*b = c; *b = (char)c;
return 0; return 0;
} }
*b = '9'; *b = '9';
...@@ -173,7 +173,7 @@ xfmtexp(char *p, int e, int ucase) ...@@ -173,7 +173,7 @@ xfmtexp(char *p, int e, int ucase)
*p++ = '+'; *p++ = '+';
i = 0; i = 0;
while(e) { while(e) {
se[i++] = e % 10 + '0'; se[i++] = (char)(e % 10 + '0');
e /= 10; e /= 10;
} }
while(i < 2) while(i < 2)
...@@ -192,7 +192,8 @@ xfmtexp(char *p, int e, int ucase) ...@@ -192,7 +192,8 @@ xfmtexp(char *p, int e, int ucase)
static void static void
xdtoa(double f, char *s, int *exp, int *neg, int *ns) xdtoa(double f, char *s, int *exp, int *neg, int *ns)
{ {
int c, d, e2, e, ee, i, ndigit, oerrno; int d, e2, e, ee, i, ndigit, oerrno;
char c;
char tmp[NSIGNIF+10]; char tmp[NSIGNIF+10];
double g; double g;
...@@ -239,7 +240,7 @@ xdtoa(double f, char *s, int *exp, int *neg, int *ns) ...@@ -239,7 +240,7 @@ xdtoa(double f, char *s, int *exp, int *neg, int *ns)
*/ */
for(i=0; i<NSIGNIF; i++) { for(i=0; i<NSIGNIF; i++) {
d = (int)g; d = (int)g;
s[i] = d+'0'; s[i] = (char)(d+'0');
g = (g-d) * 10; g = (g-d) * 10;
} }
s[i] = 0; s[i] = 0;
...@@ -350,12 +351,13 @@ __efgfmt(Fmt *fmt) ...@@ -350,12 +351,13 @@ __efgfmt(Fmt *fmt)
{ {
char buf[NSIGNIF+10], *dot, *digits, *p, *s, suf[10], *t; char buf[NSIGNIF+10], *dot, *digits, *p, *s, suf[10], *t;
double f; double f;
int c, chr, dotwid, e, exp, fl, ndigits, neg, newndigits; int c, chr, dotwid, e, exp, ndigits, neg, newndigits;
int pad, point, prec, realchr, sign, sufwid, ucase, wid, z1, z2; int pad, point, prec, realchr, sign, sufwid, ucase, wid, z1, z2;
ulong fl;
Rune r, *rs, *rt; Rune r, *rs, *rt;
if(fmt->flags&FmtLong) if(fmt->flags&FmtLong)
f = va_arg(fmt->args, long double); f = (double)va_arg(fmt->args, long double);
else else
f = va_arg(fmt->args, double); f = va_arg(fmt->args, double);
...@@ -367,7 +369,7 @@ __efgfmt(Fmt *fmt) ...@@ -367,7 +369,7 @@ __efgfmt(Fmt *fmt)
prec = FDEFLT; prec = FDEFLT;
if(fl & FmtPrec) if(fl & FmtPrec)
prec = fmt->prec; prec = fmt->prec;
chr = fmt->r; chr = (int)fmt->r;
ucase = 0; ucase = 0;
switch(chr) { switch(chr) {
case 'A': case 'A':
...@@ -386,7 +388,7 @@ __efgfmt(Fmt *fmt) ...@@ -386,7 +388,7 @@ __efgfmt(Fmt *fmt)
s = special[0+ucase]; s = special[0+ucase];
special: special:
fmt->flags = fl & (FmtWidth|FmtLeft); fmt->flags = fl & (FmtWidth|FmtLeft);
return __fmtcpy(fmt, s, strlen(s), strlen(s)); return __fmtcpy(fmt, s, (int)strlen(s), (int)strlen(s));
} }
if(__isInf(f, 1)) { if(__isInf(f, 1)) {
s = special[2+ucase]; s = special[2+ucase];
...@@ -488,7 +490,7 @@ __efgfmt(Fmt *fmt) ...@@ -488,7 +490,7 @@ __efgfmt(Fmt *fmt)
z2 = 0; z2 = 0;
} }
xfmtexp(suf, e, ucase); xfmtexp(suf, e, ucase);
sufwid = strlen(suf); sufwid = (int)strlen(suf);
break; break;
casef: casef:
...@@ -638,7 +640,7 @@ __efgfmt(Fmt *fmt) ...@@ -638,7 +640,7 @@ __efgfmt(Fmt *fmt)
} }
} }
} }
fmt->nfmt += rt - (Rune*)fmt->to; fmt->nfmt += (int)(rt - (Rune*)fmt->to);
fmt->to = rt; fmt->to = rt;
if(sufwid && __fmtcpy(fmt, suf, sufwid, sufwid) < 0) if(sufwid && __fmtcpy(fmt, suf, sufwid, sufwid) < 0)
return -1; return -1;
...@@ -667,7 +669,7 @@ __efgfmt(Fmt *fmt) ...@@ -667,7 +669,7 @@ __efgfmt(Fmt *fmt)
for(p=dot; *p; p++) for(p=dot; *p; p++)
FMTCHAR(fmt, t, s, *p); FMTCHAR(fmt, t, s, *p);
} }
fmt->nfmt += t - (char*)fmt->to; fmt->nfmt += (int)(t - (char*)fmt->to);
fmt->to = t; fmt->to = t;
if(sufwid && __fmtcpy(fmt, suf, sufwid, sufwid) < 0) if(sufwid && __fmtcpy(fmt, suf, sufwid, sufwid) < 0)
return -1; return -1;
......
...@@ -187,12 +187,12 @@ __fmtdispatch(Fmt *f, void *fmt, int isrunes) ...@@ -187,12 +187,12 @@ __fmtdispatch(Fmt *f, void *fmt, int isrunes)
case '5': case '6': case '7': case '8': case '9': case '5': case '6': case '7': case '8': case '9':
i = 0; i = 0;
while(r >= '0' && r <= '9'){ while(r >= '0' && r <= '9'){
i = i * 10 + r - '0'; i = i * 10 + (int)r - '0';
if(isrunes){ if(isrunes){
r = *(Rune*)fmt; r = *(Rune*)fmt;
fmt = (Rune*)fmt + 1; fmt = (Rune*)fmt + 1;
}else{ }else{
r = *(char*)fmt; r = (Rune)*(char*)fmt;
fmt = (char*)fmt + 1; fmt = (char*)fmt + 1;
} }
} }
...@@ -217,7 +217,7 @@ __fmtdispatch(Fmt *f, void *fmt, int isrunes) ...@@ -217,7 +217,7 @@ __fmtdispatch(Fmt *f, void *fmt, int isrunes)
* ignore the precision. * ignore the precision.
*/ */
if(f->flags & FmtPrec){ if(f->flags & FmtPrec){
f->flags &= ~FmtPrec; f->flags &= ~(ulong)FmtPrec;
f->prec = 0; f->prec = 0;
continue; continue;
} }
...@@ -226,7 +226,7 @@ __fmtdispatch(Fmt *f, void *fmt, int isrunes) ...@@ -226,7 +226,7 @@ __fmtdispatch(Fmt *f, void *fmt, int isrunes)
} }
goto numflag; goto numflag;
} }
n = (*fmtfmt(r))(f); n = (*fmtfmt((int)r))(f);
if(n < 0) if(n < 0)
return nil; return nil;
if(n == 0) if(n == 0)
......
...@@ -75,7 +75,7 @@ int __strfmt(Fmt *f); ...@@ -75,7 +75,7 @@ int __strfmt(Fmt *f);
else\ else\
return -1;\ return -1;\
}\ }\
*t++ = c;\ *t++ = (char)c;\
}while(0) }while(0)
#define FMTRCHAR(f, t, s, c)\ #define FMTRCHAR(f, t, s, c)\
...@@ -87,7 +87,7 @@ int __strfmt(Fmt *f); ...@@ -87,7 +87,7 @@ int __strfmt(Fmt *f);
else\ else\
return -1;\ return -1;\
}\ }\
*t++ = c;\ *t++ = (Rune)c;\
}while(0) }while(0)
#define FMTRUNE(f, t, s, r)\ #define FMTRUNE(f, t, s, r)\
...@@ -102,7 +102,7 @@ int __strfmt(Fmt *f); ...@@ -102,7 +102,7 @@ int __strfmt(Fmt *f);
return -1;\ return -1;\
}\ }\
if(r < Runeself)\ if(r < Runeself)\
*t++ = r;\ *t++ = (char)r;\
else{\ else{\
_rune = r;\ _rune = r;\
t += runetochar(t, &_rune);\ t += runetochar(t, &_rune);\
......
...@@ -29,8 +29,8 @@ __fmtFdFlush(Fmt *f) ...@@ -29,8 +29,8 @@ __fmtFdFlush(Fmt *f)
{ {
int n; int n;
n = (char*)f->to - (char*)f->start; n = (int)((char*)f->to - (char*)f->start);
if(n && write((uintptr)f->farg, f->start, n) != n) if(n && (int)write((int)(uintptr)f->farg, f->start, (size_t)n) != n)
return 0; return 0;
f->to = f->start; f->to = f->start;
return 1; return 1;
......
...@@ -69,7 +69,7 @@ __quotesetup(char *s, Rune *r, int nin, int nout, Quoteinfo *q, int sharp, int r ...@@ -69,7 +69,7 @@ __quotesetup(char *s, Rune *r, int nin, int nout, Quoteinfo *q, int sharp, int r
break; break;
} }
if((c <= L' ') || (c == L'\'') || (fmtdoquote!=nil && fmtdoquote(c))){ if((c <= L' ') || (c == L'\'') || (fmtdoquote!=nil && fmtdoquote((int)c))){
if(!q->quoted){ if(!q->quoted){
if(runesout){ if(runesout){
if(1+q->nrunesout+1+1 > nout) /* no room for quotes */ if(1+q->nrunesout+1+1 > nout) /* no room for quotes */
...@@ -152,7 +152,7 @@ qstrfmt(char *sin, Rune *rin, Quoteinfo *q, Fmt *f) ...@@ -152,7 +152,7 @@ qstrfmt(char *sin, Rune *rin, Quoteinfo *q, Fmt *f)
r = *(uchar*)m; r = *(uchar*)m;
if(r < Runeself) if(r < Runeself)
m++; m++;
else if((me - m) >= UTFmax || fullrune(m, me-m)) else if((me - m) >= UTFmax || fullrune(m, (int)(me-m)))
m += chartorune(&r, m); m += chartorune(&r, m);
else else
break; break;
...@@ -175,14 +175,14 @@ qstrfmt(char *sin, Rune *rin, Quoteinfo *q, Fmt *f) ...@@ -175,14 +175,14 @@ qstrfmt(char *sin, Rune *rin, Quoteinfo *q, Fmt *f)
if(f->runes){ if(f->runes){
FMTRCHAR(f, rt, rs, '\''); FMTRCHAR(f, rt, rs, '\'');
USED(rs); USED(rs);
f->nfmt += rt - (Rune *)f->to; f->nfmt += (int)(rt - (Rune *)f->to);
f->to = rt; f->to = rt;
if(fl & FmtLeft && __rfmtpad(f, w - q->nrunesout) < 0) if(fl & FmtLeft && __rfmtpad(f, w - q->nrunesout) < 0)
return -1; return -1;
}else{ }else{
FMTRUNE(f, t, s, '\''); FMTRUNE(f, t, s, '\'');
USED(s); USED(s);
f->nfmt += t - (char *)f->to; f->nfmt += (int)(t - (char *)f->to);
f->to = t; f->to = t;
if(fl & FmtLeft && __fmtpad(f, w - q->nbytesout) < 0) if(fl & FmtLeft && __fmtpad(f, w - q->nbytesout) < 0)
return -1; return -1;
...@@ -214,9 +214,9 @@ __quotestrfmt(int runesin, Fmt *f) ...@@ -214,9 +214,9 @@ __quotestrfmt(int runesin, Fmt *f)
if(f->flush) if(f->flush)
outlen = 0x7FFFFFFF; /* if we can flush, no output limit */ outlen = 0x7FFFFFFF; /* if we can flush, no output limit */
else if(f->runes) else if(f->runes)
outlen = (Rune*)f->stop - (Rune*)f->to; outlen = (int)((Rune*)f->stop - (Rune*)f->to);
else else
outlen = (char*)f->stop - (char*)f->to; outlen = (int)((char*)f->stop - (char*)f->to);
__quotesetup(s, r, nin, outlen, &q, f->flags&FmtSharp, f->runes); __quotesetup(s, r, nin, outlen, &q, f->flags&FmtSharp, f->runes);
/*print("bytes in %d bytes out %d runes in %d runesout %d\n", q.nbytesin, q.nbytesout, q.nrunesin, q.nrunesout); */ /*print("bytes in %d bytes out %d runes in %d runesout %d\n", q.nbytesin, q.nbytesout, q.nrunesin, q.nrunesout); */
......
...@@ -34,8 +34,8 @@ fmtrune(Fmt *f, int r) ...@@ -34,8 +34,8 @@ fmtrune(Fmt *f, int r)
n = 1; n = 1;
}else{ }else{
t = (char*)f->to; t = (char*)f->to;
FMTRUNE(f, t, f->stop, r); FMTRUNE(f, t, f->stop, (Rune)r);
n = t - (char*)f->to; n = (int)(t - (char*)f->to);
f->to = t; f->to = t;
} }
f->nfmt += n; f->nfmt += n;
......
...@@ -36,10 +36,10 @@ sprint(char *buf, char *fmt, ...) ...@@ -36,10 +36,10 @@ sprint(char *buf, char *fmt, ...)
* optimizes the test away. casting to uintptr works around this bug. * optimizes the test away. casting to uintptr works around this bug.
*/ */
if((uintptr)buf+len < (uintptr)buf) if((uintptr)buf+len < (uintptr)buf)
len = -(uintptr)buf-1; len = (uint)-(uintptr)buf-1;
va_start(args, fmt); va_start(args, fmt);
n = vsnprint(buf, len, fmt, args); n = (int)vsnprint(buf, (int)len, fmt, args);
va_end(args); va_end(args);
return n; return n;
} }
...@@ -124,7 +124,7 @@ fmtstrtod(const char *as, char **aas) ...@@ -124,7 +124,7 @@ fmtstrtod(const char *as, char **aas)
continue; continue;
} }
if(na < Ndig-50) if(na < Ndig-50)
a[na++] = c; a[na++] = (char)c;
continue; continue;
} }
switch(c) { switch(c) {
...@@ -240,7 +240,7 @@ fmtstrtod(const char *as, char **aas) ...@@ -240,7 +240,7 @@ fmtstrtod(const char *as, char **aas)
mid[0] = 0; mid[0] = 0;
mid[1] = 1; mid[1] = 1;
for(i=0; (c=a[i]) != '\0'; i++) { for(i=0; (c=a[i]) != '\0'; i++) {
mid[0] = mid[0]*10 + (c-'0'); mid[0] = mid[0]*10 + (ulong)(c-'0');
mid[1] = mid[1]*10; mid[1] = mid[1]*10;
if(i >= 8) if(i >= 8)
break; break;
...@@ -287,13 +287,13 @@ fmtstrtod(const char *as, char **aas) ...@@ -287,13 +287,13 @@ fmtstrtod(const char *as, char **aas)
/* only hard part is if even/odd roundings wants to go up */ /* only hard part is if even/odd roundings wants to go up */
c = mid[Prec-1] & (Sigbit-1); c = mid[Prec-1] & (Sigbit-1);
if(c == Sigbit/2 && (mid[Prec-1]&Sigbit) == 0) if(c == Sigbit/2 && (mid[Prec-1]&Sigbit) == 0)
mid[Prec-1] -= c; mid[Prec-1] -= (ulong)c;
break; /* exactly mid */ break; /* exactly mid */
} }
/* normal rounding applies */ /* normal rounding applies */
c = mid[Prec-1] & (Sigbit-1); c = mid[Prec-1] & (Sigbit-1);
mid[Prec-1] -= c; mid[Prec-1] -= (ulong)c;
if(c >= Sigbit/2) { if(c >= Sigbit/2) {
mid[Prec-1] += Sigbit; mid[Prec-1] += Sigbit;
frnorm(mid); frnorm(mid);
...@@ -317,7 +317,7 @@ retinf: ...@@ -317,7 +317,7 @@ retinf:
out: out:
d = 0; d = 0;
for(i=0; i<Prec; i++) for(i=0; i<Prec; i++)
d = d*One + mid[i]; d = d*One + (double)mid[i];
if(flag & Fsign) if(flag & Fsign)
d = -d; d = -d;
d = ldexp(d, bp - Prec*Nbits); d = ldexp(d, bp - Prec*Nbits);
...@@ -330,7 +330,8 @@ out: ...@@ -330,7 +330,8 @@ out:
static void static void
frnorm(ulong *f) frnorm(ulong *f)
{ {
int i, c; int i;
ulong c;
c = 0; c = 0;
for(i=Prec-1; i>0; i--) { for(i=Prec-1; i>0; i--) {
...@@ -355,7 +356,7 @@ fpcmp(char *a, ulong* f) ...@@ -355,7 +356,7 @@ fpcmp(char *a, ulong* f)
for(i=0; i<Prec; i++) for(i=0; i<Prec; i++)
tf[i] = tf[i]*10; tf[i] = tf[i]*10;
frnorm(tf); frnorm(tf);
d = (tf[0] >> Nbits) + '0'; d = (int)(tf[0] >> Nbits) + '0';
tf[0] &= One-1; tf[0] &= One-1;
/* compare next digit */ /* compare next digit */
...@@ -404,7 +405,7 @@ divby(char *a, int *na, int b) ...@@ -404,7 +405,7 @@ divby(char *a, int *na, int b)
for(;;) { for(;;) {
c = n>>b; c = n>>b;
n -= c<<b; n -= c<<b;
*p++ = c + '0'; *p++ = (char)(c + '0');
c = *a++; c = *a++;
if(c == 0) if(c == 0)
break; break;
...@@ -416,7 +417,7 @@ xx: ...@@ -416,7 +417,7 @@ xx:
n = n*10; n = n*10;
c = n>>b; c = n>>b;
n -= c<<b; n -= c<<b;
*p++ = c + '0'; *p++ = (char)(c + '0');
(*na)++; (*na)++;
} }
*p = 0; *p = 0;
...@@ -447,7 +448,7 @@ divascii(char *a, int *na, int *dp, int *bp) ...@@ -447,7 +448,7 @@ divascii(char *a, int *na, int *dp, int *bp)
d = (int)(nelem(tab1))-1; d = (int)(nelem(tab1))-1;
t = tab1 + d; t = tab1 + d;
b = t->bp; b = t->bp;
if(memcmp(a, t->cmp, t->siz) > 0) if(memcmp(a, t->cmp, (size_t)t->siz) > 0)
d--; d--;
*dp -= d; *dp -= d;
*bp += b; *bp += b;
...@@ -470,14 +471,14 @@ mulby(char *a, char *p, char *q, int b) ...@@ -470,14 +471,14 @@ mulby(char *a, char *p, char *q, int b)
n = c/10; n = c/10;
c -= n*10; c -= n*10;
p--; p--;
*p = c + '0'; *p = (char)(c + '0');
} }
while(n) { while(n) {
c = n; c = n;
n = c/10; n = c/10;
c -= n*10; c -= n*10;
p--; p--;
*p = c + '0'; *p = (char)(c + '0');
} }
} }
...@@ -507,7 +508,7 @@ mulascii(char *a, int *na, int *dp, int *bp) ...@@ -507,7 +508,7 @@ mulascii(char *a, int *na, int *dp, int *bp)
d = (int)(nelem(tab2))-1; d = (int)(nelem(tab2))-1;
t = tab2 + d; t = tab2 + d;
b = t->bp; b = t->bp;
if(memcmp(a, t->cmp, t->siz) < 0) if(memcmp(a, t->cmp, (size_t)t->siz) < 0)
d--; d--;
p = a + *na; p = a + *na;
*bp -= b; *bp -= b;
......
...@@ -28,10 +28,10 @@ fmtStrFlush(Fmt *f) ...@@ -28,10 +28,10 @@ fmtStrFlush(Fmt *f)
if(f->start == nil) if(f->start == nil)
return 0; return 0;
n = (uintptr)f->farg; n = (int)(uintptr)f->farg;
n *= 2; n *= 2;
s = (char*)f->start; s = (char*)f->start;
f->start = realloc(s, n); f->start = realloc(s, (size_t)n);
if(f->start == nil){ if(f->start == nil){
f->farg = nil; f->farg = nil;
f->to = nil; f->to = nil;
...@@ -53,7 +53,7 @@ fmtstrinit(Fmt *f) ...@@ -53,7 +53,7 @@ fmtstrinit(Fmt *f)
memset(f, 0, sizeof *f); memset(f, 0, sizeof *f);
f->runes = 0; f->runes = 0;
n = 32; n = 32;
f->start = malloc(n); f->start = malloc((size_t)n);
if(f->start == nil) if(f->start == nil)
return -1; return -1;
f->to = f->start; f->to = f->start;
......
...@@ -39,5 +39,5 @@ vsnprint(char *buf, int len, char *fmt, va_list args) ...@@ -39,5 +39,5 @@ vsnprint(char *buf, int len, char *fmt, va_list args)
dofmt(&f, fmt); dofmt(&f, fmt);
VA_END(f.args); VA_END(f.args);
*(char*)f.to = '\0'; *(char*)f.to = '\0';
return (char*)f.to - buf; return (int)((char*)f.to - buf);
} }
...@@ -50,5 +50,5 @@ p9getwd(char *s, int ns) ...@@ -50,5 +50,5 @@ p9getwd(char *s, int ns)
return s; return s;
} }
return getcwd(s, ns); return getcwd(s, (size_t)ns);
} }
...@@ -36,7 +36,7 @@ readn(int f, void *av, long n) ...@@ -36,7 +36,7 @@ readn(int f, void *av, long n)
a = av; a = av;
t = 0; t = 0;
while(t < n){ while(t < n){
m = read(f, a+t, n-t); m = read(f, a+t, (size_t)(n-t));
if(m <= 0){ if(m <= 0){
if(t == 0) if(t == 0)
return m; return m;
......
...@@ -82,7 +82,7 @@ p9rfork(int flags) ...@@ -82,7 +82,7 @@ p9rfork(int flags)
close(p[0]); close(p[0]);
return -1; return -1;
} }
n = readn(p[0], buf, sizeof buf-1); n = (int)readn(p[0], buf, sizeof buf-1);
close(p[0]); close(p[0]);
if(!WIFEXITED(status) || WEXITSTATUS(status)!=0 || n <= 0){ if(!WIFEXITED(status) || WEXITSTATUS(status)!=0 || n <= 0){
if(!WIFEXITED(status)) if(!WIFEXITED(status))
...@@ -102,7 +102,7 @@ p9rfork(int flags) ...@@ -102,7 +102,7 @@ p9rfork(int flags)
werrstr("%s", buf+2); werrstr("%s", buf+2);
return -1; return -1;
} }
pid = strtol(buf, &q, 0); pid = (int)strtol(buf, &q, 0);
}else{ }else{
/* /*
* Child - fork a new child whose wait message can't * Child - fork a new child whose wait message can't
......
...@@ -32,7 +32,7 @@ strecpy(char *to, char *e, char *from) ...@@ -32,7 +32,7 @@ strecpy(char *to, char *e, char *from)
{ {
if(to >= e) if(to >= e)
return to; return to;
to = memccpy(to, from, '\0', e - to); to = memccpy(to, from, '\0', (size_t)(e - to));
if(to == nil){ if(to == nil){
to = e - 1; to = e - 1;
*to = '\0'; *to = '\0';
......
...@@ -37,7 +37,7 @@ qtoken(char *s, char *sep) ...@@ -37,7 +37,7 @@ qtoken(char *s, char *sep)
quoting = 0; quoting = 0;
t = s; /* s is output string, t is input string */ t = s; /* s is output string, t is input string */
while(*t!='\0' && (quoting || utfrune(sep, *t)==nil)){ while(*t!='\0' && (quoting || utfrune(sep, (Rune)*t)==nil)){
if(*t != '\''){ if(*t != '\''){
*s++ = *t++; *s++ = *t++;
continue; continue;
...@@ -74,7 +74,7 @@ etoken(char *t, char *sep) ...@@ -74,7 +74,7 @@ etoken(char *t, char *sep)
/* move to end of next token */ /* move to end of next token */
quoting = 0; quoting = 0;
while(*t!='\0' && (quoting || utfrune(sep, *t)==nil)){ while(*t!='\0' && (quoting || utfrune(sep, (Rune)*t)==nil)){
if(*t != '\''){ if(*t != '\''){
t++; t++;
continue; continue;
...@@ -104,7 +104,7 @@ gettokens(char *s, char **args, int maxargs, char *sep) ...@@ -104,7 +104,7 @@ gettokens(char *s, char **args, int maxargs, char *sep)
int nargs; int nargs;
for(nargs=0; nargs<maxargs; nargs++){ for(nargs=0; nargs<maxargs; nargs++){
while(*s!='\0' && utfrune(sep, *s)!=nil) while(*s!='\0' && utfrune(sep, (Rune)*s)!=nil)
*s++ = '\0'; *s++ = '\0';
if(*s == '\0') if(*s == '\0')
break; break;
...@@ -121,7 +121,7 @@ tokenize(char *s, char **args, int maxargs) ...@@ -121,7 +121,7 @@ tokenize(char *s, char **args, int maxargs)
int nargs; int nargs;
for(nargs=0; nargs<maxargs; nargs++){ for(nargs=0; nargs<maxargs; nargs++){
while(*s!='\0' && utfrune(qsep, *s)!=nil) while(*s!='\0' && utfrune(qsep, (Rune)*s)!=nil)
s++; s++;
if(*s == '\0') if(*s == '\0')
break; break;
......
...@@ -80,7 +80,7 @@ charntorune(Rune *rune, const char *str, int length) ...@@ -80,7 +80,7 @@ charntorune(Rune *rune, const char *str, int length)
*/ */
c = *(uchar*)str; c = *(uchar*)str;
if(c < Tx) { if(c < Tx) {
*rune = c; *rune = (Rune)c;
return 1; return 1;
} }
...@@ -102,7 +102,7 @@ charntorune(Rune *rune, const char *str, int length) ...@@ -102,7 +102,7 @@ charntorune(Rune *rune, const char *str, int length)
l = ((c << Bitx) | c1) & Rune2; l = ((c << Bitx) | c1) & Rune2;
if(l <= Rune1) if(l <= Rune1)
goto bad; goto bad;
*rune = l; *rune = (Rune)l;
return 2; return 2;
} }
...@@ -124,7 +124,7 @@ charntorune(Rune *rune, const char *str, int length) ...@@ -124,7 +124,7 @@ charntorune(Rune *rune, const char *str, int length)
goto bad; goto bad;
if (SurrogateMin <= l && l <= SurrogateMax) if (SurrogateMin <= l && l <= SurrogateMax)
goto bad; goto bad;
*rune = l; *rune = (Rune)l;
return 3; return 3;
} }
...@@ -142,7 +142,7 @@ charntorune(Rune *rune, const char *str, int length) ...@@ -142,7 +142,7 @@ charntorune(Rune *rune, const char *str, int length)
l = ((((((c << Bitx) | c1) << Bitx) | c2) << Bitx) | c3) & Rune4; l = ((((((c << Bitx) | c1) << Bitx) | c2) << Bitx) | c3) & Rune4;
if (l <= Rune3 || l > Runemax) if (l <= Rune3 || l > Runemax)
goto bad; goto bad;
*rune = l; *rune = (Rune)l;
return 4; return 4;
} }
...@@ -178,7 +178,7 @@ chartorune(Rune *rune, const char *str) ...@@ -178,7 +178,7 @@ chartorune(Rune *rune, const char *str)
*/ */
c = *(uchar*)str; c = *(uchar*)str;
if(c < Tx) { if(c < Tx) {
*rune = c; *rune = (Rune)c;
return 1; return 1;
} }
...@@ -195,7 +195,7 @@ chartorune(Rune *rune, const char *str) ...@@ -195,7 +195,7 @@ chartorune(Rune *rune, const char *str)
l = ((c << Bitx) | c1) & Rune2; l = ((c << Bitx) | c1) & Rune2;
if(l <= Rune1) if(l <= Rune1)
goto bad; goto bad;
*rune = l; *rune = (Rune)l;
return 2; return 2;
} }
...@@ -212,7 +212,7 @@ chartorune(Rune *rune, const char *str) ...@@ -212,7 +212,7 @@ chartorune(Rune *rune, const char *str)
goto bad; goto bad;
if (SurrogateMin <= l && l <= SurrogateMax) if (SurrogateMin <= l && l <= SurrogateMax)
goto bad; goto bad;
*rune = l; *rune = (Rune)l;
return 3; return 3;
} }
...@@ -227,7 +227,7 @@ chartorune(Rune *rune, const char *str) ...@@ -227,7 +227,7 @@ chartorune(Rune *rune, const char *str)
l = ((((((c << Bitx) | c1) << Bitx) | c2) << Bitx) | c3) & Rune4; l = ((((((c << Bitx) | c1) << Bitx) | c2) << Bitx) | c3) & Rune4;
if (l <= Rune3 || l > Runemax) if (l <= Rune3 || l > Runemax)
goto bad; goto bad;
*rune = l; *rune = (Rune)l;
return 4; return 4;
} }
...@@ -263,7 +263,7 @@ runetochar(char *str, const Rune *rune) ...@@ -263,7 +263,7 @@ runetochar(char *str, const Rune *rune)
*/ */
c = *rune; c = *rune;
if(c <= Rune1) { if(c <= Rune1) {
str[0] = c; str[0] = (char)c;
return 1; return 1;
} }
...@@ -272,8 +272,8 @@ runetochar(char *str, const Rune *rune) ...@@ -272,8 +272,8 @@ runetochar(char *str, const Rune *rune)
* 0080-07FF => T2 Tx * 0080-07FF => T2 Tx
*/ */
if(c <= Rune2) { if(c <= Rune2) {
str[0] = T2 | (c >> 1*Bitx); str[0] = (char)(T2 | (c >> 1*Bitx));
str[1] = Tx | (c & Maskx); str[1] = (char)(Tx | (c & Maskx));
return 2; return 2;
} }
...@@ -293,9 +293,9 @@ runetochar(char *str, const Rune *rune) ...@@ -293,9 +293,9 @@ runetochar(char *str, const Rune *rune)
* 0800-FFFF => T3 Tx Tx * 0800-FFFF => T3 Tx Tx
*/ */
if (c <= Rune3) { if (c <= Rune3) {
str[0] = T3 | (c >> 2*Bitx); str[0] = (char)(T3 | (c >> 2*Bitx));
str[1] = Tx | ((c >> 1*Bitx) & Maskx); str[1] = (char)(Tx | ((c >> 1*Bitx) & Maskx));
str[2] = Tx | (c & Maskx); str[2] = (char)(Tx | (c & Maskx));
return 3; return 3;
} }
...@@ -303,10 +303,10 @@ runetochar(char *str, const Rune *rune) ...@@ -303,10 +303,10 @@ runetochar(char *str, const Rune *rune)
* four character sequence (21-bit value) * four character sequence (21-bit value)
* 10000-1FFFFF => T4 Tx Tx Tx * 10000-1FFFFF => T4 Tx Tx Tx
*/ */
str[0] = T4 | (c >> 3*Bitx); str[0] = (char)(T4 | (c >> 3*Bitx));
str[1] = Tx | ((c >> 2*Bitx) & Maskx); str[1] = (char)(Tx | ((c >> 2*Bitx) & Maskx));
str[2] = Tx | ((c >> 1*Bitx) & Maskx); str[2] = (char)(Tx | ((c >> 1*Bitx) & Maskx));
str[3] = Tx | (c & Maskx); str[3] = (char)(Tx | (c & Maskx));
return 4; return 4;
} }
...@@ -325,7 +325,7 @@ runenlen(const Rune *r, int nrune) ...@@ -325,7 +325,7 @@ runenlen(const Rune *r, int nrune)
nb = 0; nb = 0;
while(nrune--) { while(nrune--) {
c = *r++; c = (int)*r++;
if (c <= Rune1) if (c <= Rune1)
nb++; nb++;
else if (c <= Rune2) else if (c <= Rune2)
......
...@@ -23,7 +23,7 @@ utfecpy(char *to, char *e, const char *from) ...@@ -23,7 +23,7 @@ utfecpy(char *to, char *e, const char *from)
if(to >= e) if(to >= e)
return to; return to;
end = memccpy(to, from, '\0', e - to); end = memccpy(to, from, '\0', (size_t)(e - to));
if(end == nil){ if(end == nil){
end = e-1; end = e-1;
while(end>to && (*--end&0xC0)==0x80) while(end>to && (*--end&0xC0)==0x80)
......
...@@ -18,7 +18,7 @@ int ...@@ -18,7 +18,7 @@ int
utflen(const char *s) utflen(const char *s)
{ {
int c; int c;
long n; int n;
Rune rune; Rune rune;
n = 0; n = 0;
......
...@@ -18,7 +18,7 @@ int ...@@ -18,7 +18,7 @@ int
utfnlen(const char *s, long m) utfnlen(const char *s, long m)
{ {
int c; int c;
long n; int n;
Rune rune; Rune rune;
const char *es; const char *es;
...@@ -31,7 +31,7 @@ utfnlen(const char *s, long m) ...@@ -31,7 +31,7 @@ utfnlen(const char *s, long m)
s++; s++;
continue; continue;
} }
if(!fullrune(s, es-s)) if(!fullrune(s, (int)(es-s)))
break; break;
s += chartorune(&rune, s); s += chartorune(&rune, s);
} }
......
...@@ -24,7 +24,7 @@ utfrrune(const char *s, Rune c) ...@@ -24,7 +24,7 @@ utfrrune(const char *s, Rune c)
const char *s1; const char *s1;
if(c < Runesync) /* not part of utf sequence */ if(c < Runesync) /* not part of utf sequence */
return strrchr(s, c); return strrchr(s, (char)c);
s1 = 0; s1 = 0;
for(;;) { for(;;) {
......
...@@ -24,7 +24,7 @@ utfrune(const char *s, Rune c) ...@@ -24,7 +24,7 @@ utfrune(const char *s, Rune c)
int n; int n;
if(c < Runesync) /* not part of utf sequence */ if(c < Runesync) /* not part of utf sequence */
return strchr(s, c); return strchr(s, (char)c);
for(;;) { for(;;) {
c1 = *(uchar*)s; c1 = *(uchar*)s;
......
...@@ -25,7 +25,8 @@ char* ...@@ -25,7 +25,8 @@ char*
utfutf(const char *s1, const char *s2) utfutf(const char *s1, const char *s2)
{ {
const char *p; const char *p;
long f, n1, n2; long f, n1;
size_t n2;
Rune r; Rune r;
n1 = chartorune(&r, s2); n1 = chartorune(&r, s2);
...@@ -34,7 +35,7 @@ utfutf(const char *s1, const char *s2) ...@@ -34,7 +35,7 @@ utfutf(const char *s1, const char *s2)
return strstr(s1, s2); return strstr(s1, s2);
n2 = strlen(s2); n2 = strlen(s2);
for(p=s1; (p=utfrune(p, f)) != 0; p+=n1) for(p=s1; (p=utfrune(p, r)) != 0; p+=n1)
if(strncmp(p, s2, n2) == 0) if(strncmp(p, s2, n2) == 0)
return p; return p;
return 0; return 0;
......
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