Changes in uspace/lib/c/generic/malloc.c [dd50aa19:ffccdff0] in mainline
- File:
-
- 1 edited
-
uspace/lib/c/generic/malloc.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/malloc.c
rdd50aa19 rffccdff0 34 34 */ 35 35 36 #include < stdlib.h>36 #include <malloc.h> 37 37 #include <stdalign.h> 38 38 #include <stdbool.h> 39 39 #include <stddef.h> 40 #include <stdio.h>41 40 #include <as.h> 42 41 #include <align.h> … … 48 47 #include <stdlib.h> 49 48 #include <adt/gcdlcm.h> 50 #include <malloc.h>51 49 52 50 #include "private/malloc.h" … … 726 724 * 727 725 */ 728 static void *malloc_internal( size_t size,size_t align)726 static void *malloc_internal(const size_t size, const size_t align) 729 727 { 730 728 malloc_assert(first_heap_area != NULL); 731 729 732 if (size == 0)733 size = 1;734 735 730 if (align == 0) 736 align = BASE_ALIGN;731 return NULL; 737 732 738 733 size_t falign = lcm(align, BASE_ALIGN); … … 778 773 } 779 774 775 /** Allocate memory by number of elements 776 * 777 * @param nmemb Number of members to allocate. 778 * @param size Size of one member in bytes. 779 * 780 * @return Allocated memory or NULL. 781 * 782 */ 783 void *calloc(const size_t nmemb, const size_t size) 784 { 785 // FIXME: Check for overflow 786 787 void *block = malloc(nmemb * size); 788 if (block == NULL) 789 return NULL; 790 791 memset(block, 0, nmemb * size); 792 return block; 793 } 794 780 795 /** Allocate memory 781 796 * … … 825 840 * 826 841 */ 827 void *realloc(void *const addr, size_t size)842 void *realloc(void *const addr, const size_t size) 828 843 { 829 844 if (size == 0) { 830 f printf(stderr, "realloc() called with size 0\n");831 size = 1;845 free(addr); 846 return NULL; 832 847 } 833 848 … … 934 949 } 935 950 936 /** Reallocate memory for an array937 *938 * Same as realloc(ptr, nelem * elsize), except the multiplication is checked939 * for numerical overflow. Borrowed from POSIX 2024.940 *941 * @param ptr942 * @param nelem943 * @param elsize944 *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 955 951 /** Free a memory block 956 952 *
Note:
See TracChangeset
for help on using the changeset viewer.
