From ed354867a954013acf9077ab15b572665220822a Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Fri, 26 Sep 2014 14:13:17 +0900 Subject: [PATCH] suppress warnings of implicit size_t <-> int conversion (blob.c) --- blob.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/blob.c b/blob.c index d98187eb..e927f4ff 100644 --- a/blob.c +++ b/blob.c @@ -67,7 +67,10 @@ pic_blob_make_bytevector(pic_state *pic) if (b < 0 || b > 255) pic_errorf(pic, "byte out of range"); - blob = pic_make_blob(pic, k); + if (k < 0) + pic_errorf(pic, "make-bytevector: cannot create a bytevector of length %d", k); + + blob = pic_make_blob(pic, (size_t)k); for (i = 0; i < k; ++i) { blob->data[i] = (unsigned char)b; } @@ -82,7 +85,7 @@ pic_blob_bytevector_length(pic_state *pic) pic_get_args(pic, "b", &bv); - return pic_int_value(bv->len); + return pic_int_value((int)bv->len); } static pic_value @@ -123,7 +126,7 @@ pic_blob_bytevector_copy_i(pic_state *pic) case 3: start = 0; case 4: - end = from->len; + end = (int)from->len; } if (to == from && (start <= at && at < end)) { @@ -146,7 +149,7 @@ static pic_value pic_blob_bytevector_copy(pic_state *pic) { pic_blob *from, *to; - int n, start, end, i = 0; + int n, start, end, k, i = 0; n = pic_get_args(pic, "b|ii", &from, &start, &end); @@ -154,10 +157,15 @@ pic_blob_bytevector_copy(pic_state *pic) case 1: start = 0; case 2: - end = from->len; + end = (int)from->len; } - to = pic_make_blob(pic, end - start); + k = end - start; + + if (k < 0) + pic_errorf(pic, "make-bytevector: cannot create a bytevector of length %d", k); + + to = pic_make_blob(pic, (size_t)k); while (start < end) { to->data[i++] = from->data[start++]; } @@ -202,7 +210,7 @@ pic_blob_list_to_bytevector(pic_state *pic) pic_get_args(pic, "o", &list); - blob = pic_make_blob(pic, pic_length(pic, list)); + blob = pic_make_blob(pic, (size_t)pic_length(pic, list)); data = blob->data; @@ -230,7 +238,7 @@ pic_blob_bytevector_to_list(pic_state *pic) case 1: start = 0; case 2: - end = blob->len; + end = (int)blob->len; } list = pic_nil_value();