Changeset dd50aa19 in mainline
- Timestamp:
- 2024-09-12T12:35:23Z (2 months ago)
- Branches:
- master
- Children:
- 899bdfd
- Parents:
- 2ee6351
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2024-09-11 13:51:11)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2024-09-12 12:35:23)
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
common/include/stdlib.h
r2ee6351 rdd50aa19 122 122 __attribute__((malloc)); 123 123 124 extern void *reallocarray(void *ptr, size_t nelem, size_t elsize) 125 __attribute__((warn_unused_result)); 126 124 127 __HELENOS_DECLS_END; 125 128 #endif -
kernel/generic/src/mm/malloc.c
r2ee6351 rdd50aa19 211 211 void *realloc(void *old_obj, size_t new_size) 212 212 { 213 if (new_size == 0) 214 new_size = 1; 215 213 216 if (!old_obj) 214 217 return malloc(new_size); -
uspace/lib/c/generic/malloc.c
r2ee6351 rdd50aa19 38 38 #include <stdbool.h> 39 39 #include <stddef.h> 40 #include <stdio.h> 40 41 #include <as.h> 41 42 #include <align.h> … … 725 726 * 726 727 */ 727 static void *malloc_internal( const size_t size, constsize_t align)728 static void *malloc_internal(size_t size, size_t align) 728 729 { 729 730 malloc_assert(first_heap_area != NULL); 730 731 732 if (size == 0) 733 size = 1; 734 731 735 if (align == 0) 732 return NULL;736 align = BASE_ALIGN; 733 737 734 738 size_t falign = lcm(align, BASE_ALIGN); … … 821 825 * 822 826 */ 823 void *realloc(void *const addr, constsize_t size)827 void *realloc(void *const addr, size_t size) 824 828 { 825 829 if (size == 0) { 826 f ree(addr);827 return NULL;830 fprintf(stderr, "realloc() called with size 0\n"); 831 size = 1; 828 832 } 829 833 … … 930 934 } 931 935 936 /** Reallocate memory for an array 937 * 938 * Same as realloc(ptr, nelem * elsize), except the multiplication is checked 939 * for numerical overflow. Borrowed from POSIX 2024. 940 * 941 * @param ptr 942 * @param nelem 943 * @param elsize 944 * 945 * @return Reallocated memory or NULL. 946 */ 947 void *reallocarray(void *ptr, size_t nelem, size_t elsize) 948 { 949 if (nelem > SIZE_MAX / elsize) 950 return NULL; 951 952 return realloc(ptr, nelem * elsize); 953 } 954 932 955 /** Free a memory block 933 956 *
Note:
See TracChangeset
for help on using the changeset viewer.