Changeset ebb1489 in mainline for uspace/lib/c/generic/malloc.c
- Timestamp:
- 2024-10-13T08:23:40Z (8 weeks ago)
- Children:
- 0472cf17
- Parents:
- 2a0c827c (diff), b3b79981 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - git-author:
- boba-buba <120932204+boba-buba@…> (2024-10-13 08:23:40)
- git-committer:
- GitHub <noreply@…> (2024-10-13 08:23:40)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/malloc.c
r2a0c827c rebb1489 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.