Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************
- * Copyright (C) 2019 Alejandro Colomar Andrés *
- * SPDX-License-Identifier: LGPL-2.0-only *
- ******************************************************************************/
- __attribute__((malloc))
- inline
- void *mallocarray(ptrdiff_t nmemb, size_t size);
- inline
- void *mallocarray(ptrdiff_t nmemb, size_t size)
- {
- if (nmemb < 0)
- goto ovf;
- if ((size_t)nmemb > (SIZE_MAX / size))
- goto ovf;
- return malloc(size * (size_t)nmemb);
- ovf:
- errno = ENOMEM;
- return NULL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement