fix bugs unveiled by the previous commit

This commit is contained in:
Yuichi Nishiwaki 2015-05-30 19:57:32 +09:00
parent bad14933d2
commit 334ceb9e7c
4 changed files with 21 additions and 16 deletions

View File

@ -7,14 +7,14 @@
void
pic_panic(pic_state PIC_UNUSED(*pic), const char *msg)
{
extern void abort();
#if DEBUG
fprintf(stderr, "abort: %s\n", msg);
#else
(void)msg;
#endif
PIC_ABORT(pic);
PIC_UNREACHABLE();
}
void

View File

@ -220,9 +220,8 @@ pic_valid_int(double v)
#else
PIC_INLINE bool
pic_valid_int(int v)
pic_valid_int(int PIC_UNUSED(v))
{
PIC_UNUSED(v);
return true;
}
#endif

View File

@ -109,9 +109,9 @@ pic_get_args(pic_state *pic, const char *format, ...)
#if PIC_ENABLE_FLOAT
case 'f': {
double *f;
pic_value v;
f = va_arg(ap, double *);
pic_value v;
v = GET_OPERAND(pic, i);
switch (pic_type(v)) {
@ -129,10 +129,10 @@ pic_get_args(pic_state *pic, const char *format, ...)
case 'F': {
double *f;
bool *e;
pic_value v;
f = va_arg(ap, double *);
e = va_arg(ap, bool *);
pic_value v;
v = GET_OPERAND(pic, i);
switch (pic_type(v)) {
@ -152,10 +152,10 @@ pic_get_args(pic_state *pic, const char *format, ...)
case 'I': {
int *k;
bool *e;
pic_value v;
k = va_arg(ap, int *);
e = va_arg(ap, bool *);
pic_value v;
v = GET_OPERAND(pic, i);
switch (pic_type(v)) {
@ -175,9 +175,9 @@ pic_get_args(pic_state *pic, const char *format, ...)
#endif
case 'i': {
int *k;
pic_value v;
k = va_arg(ap, int *);
pic_value v;
v = GET_OPERAND(pic, i);
switch (pic_type(v)) {
@ -196,12 +196,12 @@ pic_get_args(pic_state *pic, const char *format, ...)
}
case 'k': {
size_t *k;
k = va_arg(ap, size_t *);
pic_value v;
int x;
size_t s;
k = va_arg(ap, size_t *);
v = GET_OPERAND(pic, i);
switch (pic_type(v)) {
case PIC_TT_INT:

View File

@ -94,6 +94,8 @@ xFILE *xfunopen(void *cookie, int (*read)(void *, char *, int), int (*write)(voi
}
int xfclose(xFILE *fp) {
extern void free(void *); /* FIXME */
xfflush(fp);
fp->flag = 0;
if (fp->base != fp->buf)
@ -102,6 +104,7 @@ int xfclose(xFILE *fp) {
}
int x_fillbuf(xFILE *fp) {
extern void *malloc(size_t); /* FIXME */
int bufsize;
if ((fp->flag & (X_READ|X_EOF|X_ERR)) != X_READ)
@ -136,6 +139,7 @@ int x_fillbuf(xFILE *fp) {
}
int x_flushbuf(int x, xFILE *fp) {
extern void *malloc(size_t); /* FIXME */
int num_written=0, bufsize=0;
char c = x;
@ -284,14 +288,15 @@ int xungetc(int c, xFILE *fp) {
}
size_t xfread(void *ptr, size_t size, size_t count, xFILE *fp) {
char *bptr = ptr;
long nbytes;
int c;
nbytes = size * count;
while (nbytes > fp->cnt) {
memcpy((char *)ptr, fp->ptr, fp->cnt);
memcpy(bptr, fp->ptr, fp->cnt);
fp->ptr += fp->cnt;
ptr += fp->cnt;
bptr += fp->cnt;
nbytes -= fp->cnt;
if ((c = x_fillbuf(fp)) == EOF) {
return (size * count - nbytes) / size;
@ -299,26 +304,27 @@ size_t xfread(void *ptr, size_t size, size_t count, xFILE *fp) {
xungetc(c, fp);
}
}
memcpy((char *)ptr, fp->ptr, nbytes);
memcpy(bptr, fp->ptr, nbytes);
fp->ptr += nbytes;
fp->cnt -= nbytes;
return count;
}
size_t xfwrite(const void *ptr, size_t size, size_t count, xFILE *fp) {
const char *bptr = ptr;
long nbytes;
nbytes = size * count;
while (nbytes > fp->cnt) {
memcpy(fp->ptr, (char *)ptr, fp->cnt);
memcpy(fp->ptr, bptr, fp->cnt);
fp->ptr += fp->cnt;
ptr += fp->cnt;
bptr += fp->cnt;
nbytes -= fp->cnt;
if (x_flushbuf(EOF, fp) == EOF) {
return (size * count - nbytes) / size;
}
}
memcpy(fp->ptr, (char *)ptr, nbytes);
memcpy(fp->ptr, bptr, nbytes);
fp->ptr += nbytes;
fp->cnt -= nbytes;
return count;