equal
deleted
inserted
replaced
38 return p >= ptr && p < limit(); |
38 return p >= ptr && p < limit(); |
39 } |
39 } |
40 |
40 |
41 void bytes::malloc(size_t len_) { |
41 void bytes::malloc(size_t len_) { |
42 len = len_; |
42 len = len_; |
43 ptr = NEW(byte, len_+1); // add trailing zero byte always |
43 ptr = NEW(byte, add_size(len_, 1)); // add trailing zero byte always |
44 if (ptr == null) { |
44 if (ptr == null) { |
45 // set ptr to some victim memory, to ease escape |
45 // set ptr to some victim memory, to ease escape |
46 set(dummy, sizeof(dummy)-1); |
46 set(dummy, sizeof(dummy)-1); |
47 unpack_abort(ERROR_ENOMEM); |
47 unpack_abort(ERROR_ENOMEM); |
48 } |
48 } |
54 if (ptr == null) { |
54 if (ptr == null) { |
55 malloc(len_); |
55 malloc(len_); |
56 return; |
56 return; |
57 } |
57 } |
58 byte* oldptr = ptr; |
58 byte* oldptr = ptr; |
59 ptr = (len_ >= PSIZE_MAX) ? null : (byte*)::realloc(ptr, len_+1); |
59 ptr = (len_ >= PSIZE_MAX) ? null : (byte*)::realloc(ptr, add_size(len_, 1)); |
60 if (ptr != null) { |
60 if (ptr != null) { |
61 mtrace('r', oldptr, 0); |
61 mtrace('r', oldptr, 0); |
62 mtrace('m', ptr, len_+1); |
62 mtrace('m', ptr, len_+1); |
63 if (len < len_) memset(ptr+len, 0, len_-len); |
63 if (len < len_) memset(ptr+len, 0, len_-len); |
64 ptr[len_] = 0; |
64 ptr[len_] = 0; |