#include <njs_core.h>
#include <string.h>
+#include <stdint.h>
typedef struct {
size = (uint64_t) length + spare;
- if (nxt_slow_path((size * sizeof(njs_value_t)) >= 0xffffffff)) {
+ if (nxt_slow_path((size * sizeof(njs_value_t)) >= UINT32_MAX)) {
goto memory_error;
}
njs_ret_t
njs_array_expand(njs_vm_t *vm, njs_array_t *array, uint32_t prepend,
- uint32_t size)
+ uint32_t new_size)
{
+ uint64_t size;
njs_value_t *start, *old;
- size += array->length;
+ size = (uint64_t) new_size + array->length;
if (nxt_fast_path(size <= array->size && prepend == 0)) {
return NXT_OK;
size += size / 2;
}
+ if (nxt_slow_path(((prepend + size) * sizeof(njs_value_t)) >= UINT32_MAX)) {
+ goto memory_error;
+ }
+
start = nxt_mem_cache_align(vm->mem_cache_pool, sizeof(njs_value_t),
(prepend + size) * sizeof(njs_value_t));
if (nxt_slow_path(start == NULL)) {
- njs_memory_error(vm);
- return NXT_ERROR;
+ goto memory_error;
}
array->size = size;
nxt_mem_cache_free(vm->mem_cache_pool, old);
return NXT_OK;
+
+memory_error:
+
+ njs_memory_error(vm);
+
+ return NXT_ERROR;
}
nxt_string("0:0,1:1,2:2,null:null,undefined:defined,false:false,"
"true:true,Infinity:Infinity,-Infinity:-Infinity,NaN:NaN,") },
+ { nxt_string("--[][3e9]"),
+ nxt_string("MemoryError") },
+
{ nxt_string("[].length"),
nxt_string("0") },
{ nxt_string("[].length = 2**32 - 1"),
nxt_string("MemoryError") },
+ { nxt_string("[].length = 3e9"),
+ nxt_string("MemoryError") },
+
{ nxt_string("Object.defineProperty([], 'length',{value: 2**32 - 1})"),
nxt_string("MemoryError") },
#include <nxt_rbtree.h>
#include <nxt_mem_cache_pool.h>
#include <string.h>
+#include <stdint.h>
/*
nxt_mem_cache_block_t *block;
/* Allocation must be less than 4G. */
- if (nxt_slow_path(size >= 0xffffffff)) {
+ if (nxt_slow_path(size >= UINT32_MAX)) {
return NULL;
}