mirror of
https://github.com/janet-lang/janet
synced 2025-01-13 17:10:27 +00:00
Simpler overflow check.
This commit is contained in:
parent
9aed578466
commit
04805d106e
@ -91,9 +91,7 @@ void janet_buffer_extra(JanetBuffer *buffer, int32_t n) {
|
|||||||
}
|
}
|
||||||
int32_t new_size = buffer->count + n;
|
int32_t new_size = buffer->count + n;
|
||||||
if (new_size > buffer->capacity) {
|
if (new_size > buffer->capacity) {
|
||||||
size_t new_capacity_sizet = (size_t) (new_size) * 2;
|
int32_t new_capacity = (new_size > (INT32_MAX / 2)) ? INT32_MAX : (new_size * 2);
|
||||||
if (new_capacity_sizet > INT32_MAX) new_capacity_sizet = INT32_MAX;
|
|
||||||
int32_t new_capacity = (int32_t) new_capacity_sizet;
|
|
||||||
uint8_t *new_data = realloc(buffer->data, new_capacity * sizeof(uint8_t));
|
uint8_t *new_data = realloc(buffer->data, new_capacity * sizeof(uint8_t));
|
||||||
janet_gcpressure(new_capacity - buffer->capacity);
|
janet_gcpressure(new_capacity - buffer->capacity);
|
||||||
if (NULL == new_data) {
|
if (NULL == new_data) {
|
||||||
|
@ -398,13 +398,13 @@ static void janet_stream_marshal(void *p, JanetMarshalContext *ctx) {
|
|||||||
duph = s->handle;
|
duph = s->handle;
|
||||||
} else {
|
} else {
|
||||||
DuplicateHandle(
|
DuplicateHandle(
|
||||||
GetCurrentProcess(),
|
GetCurrentProcess(),
|
||||||
s->handle,
|
s->handle,
|
||||||
GetCurrentProcess(),
|
GetCurrentProcess(),
|
||||||
&duph,
|
&duph,
|
||||||
0,
|
0,
|
||||||
FALSE,
|
FALSE,
|
||||||
DUPLICATE_SAME_ACCESS);
|
DUPLICATE_SAME_ACCESS);
|
||||||
}
|
}
|
||||||
janet_marshal_int64(ctx, (int64_t)(duph));
|
janet_marshal_int64(ctx, (int64_t)(duph));
|
||||||
#else
|
#else
|
||||||
|
Loading…
Reference in New Issue
Block a user