diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2022-06-06 20:01:41 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2022-06-07 14:08:30 +0300 |
commit | aabfaeb28ccbc3016aa17d0934b0affb721286cf (patch) | |
tree | f596a1f6c0807c13df602e07cbbd9da321153f14 /mallocx.c | |
parent | 0c44b469646fb07cf82a62deed6a7ee693112c8f (diff) | |
download | bdwgc-aabfaeb28ccbc3016aa17d0934b0affb721286cf.tar.gz |
Specify that internal allocations failure is unlikely
(refactoring)
* finalize.c [!GC_NO_FINALIZATION]
(GC_register_disappearing_link_inner): Assume failure of allocation
(resulting in NULL or GC_oom_fn call) is unlikely.
* malloc.c [DBG_HDRS_ALL || GC_GCJ_SUPPORT || !GC_NO_FINALIZATION]
(GC_generic_malloc_inner_ignore_off_page): Likewise.
* malloc.c (GC_generic_malloc): Likewise.
* malloc.c [REDIRECT_MALLOC && !REDIRECT_MALLOC_IN_HEADER] (calloc,
strdup, strndup): Likewise.
* mallocx.c (GC_realloc, GC_memalign, GC_strdup, GC_strndup): Likewise.
* mallocx.c [GC_REQUIRE_WCSDUP] (GC_wcsdup): Likewise.
* specific.c [USE_CUSTOM_SPECIFIC] (GC_setspecific): Likewise.
* typd_mlc.c (GC_make_sequence_descriptor, GC_make_descriptor):
Likewise.
* malloc.c [REDIRECT_MALLOC && !REDIRECT_MALLOC_IN_HEADER] (calloc):
Expect that lb and n are not greater than GC_SQRT_SIZE_MAX.
* typd_mlc.c (GC_calloc_explicitly_typed): Likewise.
* typd_mlc.c (GC_add_ext_descriptor): Assume that resizing of
GC_ext_descriptors[] is rare.
* typd_mlc.c (GC_calloc_explicitly_typed): Do not call
GC_make_array_descriptor() if n * lb > GC_SIZE_MAX.
* malloc.c [REDIRECT_MALLOC && !REDIRECT_MALLOC_IN_HEADER && !strndup]
(strndup): Expect that len is not greater than size.
* mallocx.c (GC_strndup): Likewise.
* typd_mlc.c (GC_make_sequence_descriptor): Reformat code.
Diffstat (limited to 'mallocx.c')
-rw-r--r-- | mallocx.c | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -160,7 +160,7 @@ GC_API void * GC_CALL GC_realloc(void * p, size_t lb) sz = lb; } result = GC_generic_or_special_malloc((word)lb, obj_kind); - if (result != NULL) { + if (EXPECT(result != NULL, TRUE)) { /* In case of shrink, it could also return original object. */ /* But this gives the client warning of imminent disaster. */ BCOPY(p, result, sz); @@ -507,7 +507,7 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_memalign(size_t align, size_t lb) if (align <= GRANULE_BYTES) return GC_malloc(lb); if (align >= HBLKSIZE/2 || lb >= HBLKSIZE/2) { - if (align > HBLKSIZE) { + if (EXPECT(align > HBLKSIZE, FALSE)) { return (*GC_get_oom_fn())(LONG_MAX-1024); /* Fail */ } return GC_malloc(lb <= HBLKSIZE? HBLKSIZE : lb); @@ -565,7 +565,7 @@ GC_API GC_ATTR_MALLOC char * GC_CALL GC_strdup(const char *s) if (s == NULL) return NULL; lb = strlen(s) + 1; copy = (char *)GC_malloc_atomic(lb); - if (NULL == copy) { + if (EXPECT(NULL == copy, FALSE)) { # ifndef MSWINCE errno = ENOMEM; # endif @@ -579,10 +579,10 @@ GC_API GC_ATTR_MALLOC char * GC_CALL GC_strndup(const char *str, size_t size) { char *copy; size_t len = strlen(str); /* str is expected to be non-NULL */ - if (len > size) + if (EXPECT(len > size, FALSE)) len = size; copy = (char *)GC_malloc_atomic(len + 1); - if (copy == NULL) { + if (EXPECT(NULL == copy, FALSE)) { # ifndef MSWINCE errno = ENOMEM; # endif @@ -602,7 +602,7 @@ GC_API GC_ATTR_MALLOC char * GC_CALL GC_strndup(const char *str, size_t size) size_t lb = (wcslen(str) + 1) * sizeof(wchar_t); wchar_t *copy = (wchar_t *)GC_malloc_atomic(lb); - if (copy == NULL) { + if (EXPECT(NULL == copy, FALSE)) { # ifndef MSWINCE errno = ENOMEM; # endif |