1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-26 08:20:27 +00:00

Address some windows issues in buffer.c

This commit is contained in:
Calvin Rose 2019-01-14 00:12:25 -05:00
parent 2cd489b9d4
commit 97a42ea17b

View File

@ -56,7 +56,7 @@ void janet_buffer_ensure(JanetBuffer *buffer, int32_t capacity, int32_t growth)
uint8_t *old = buffer->data; uint8_t *old = buffer->data;
if (capacity <= buffer->capacity) return; if (capacity <= buffer->capacity) return;
int64_t big_capacity = capacity * growth; int64_t big_capacity = capacity * growth;
capacity = big_capacity > INT32_MAX ? INT32_MAX : big_capacity; capacity = big_capacity > INT32_MAX ? INT32_MAX : (int32_t) big_capacity;
new_data = realloc(old, capacity * sizeof(uint8_t)); new_data = realloc(old, capacity * sizeof(uint8_t));
if (NULL == new_data) { if (NULL == new_data) {
JANET_OUT_OF_MEMORY; JANET_OUT_OF_MEMORY;
@ -249,7 +249,7 @@ static void bitloc(int32_t argc, Janet *argv, JanetBuffer **b, int32_t *index, i
if (bitindex != x || bitindex < 0 || byteindex >= buffer->count) if (bitindex != x || bitindex < 0 || byteindex >= buffer->count)
janet_panicf("invalid bit index %v", argv[1]); janet_panicf("invalid bit index %v", argv[1]);
*b = buffer; *b = buffer;
*index = byteindex; *index = (int32_t) byteindex;
*bit = which_bit; *bit = which_bit;
} }
@ -309,8 +309,8 @@ static Janet cfun_blit(int32_t argc, Janet *argv) {
int64_t last = ((int64_t) offset_dest - offset_src) + length_src; int64_t last = ((int64_t) offset_dest - offset_src) + length_src;
if (last > INT32_MAX) if (last > INT32_MAX)
janet_panic("buffer blit out of range"); janet_panic("buffer blit out of range");
janet_buffer_ensure(dest, last, 2); janet_buffer_ensure(dest, (int32_t) last, 2);
if (last > dest->count) dest->count = last; if (last > dest->count) dest->count = (int32_t) last;
memcpy(dest->data + offset_dest, src.bytes + offset_src, length_src); memcpy(dest->data + offset_dest, src.bytes + offset_src, length_src);
return argv[0]; return argv[0];
} }