1 | /* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved. |
2 | |
3 | This program is free software; you can redistribute it and/or modify |
4 | it under the terms of the GNU General Public License as published by |
5 | the Free Software Foundation; version 2 of the License. |
6 | |
7 | This program is distributed in the hope that it will be useful, |
8 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10 | GNU General Public License for more details. |
11 | |
12 | You should have received a copy of the GNU General Public License |
13 | along with this program; if not, write to the Free Software Foundation, |
14 | 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */ |
15 | |
16 | #include <my_global.h> |
17 | #include <my_sys.h> |
18 | #include <pfs_global.h> |
19 | |
20 | bool pfs_initialized= false; |
21 | |
22 | void *pfs_malloc(size_t size, myf flags) |
23 | { |
24 | void *ptr= malloc(size); |
25 | if (ptr && (flags & MY_ZEROFILL)) |
26 | memset(ptr, 0, size); |
27 | return ptr; |
28 | } |
29 | |
30 | void pfs_free(void *ptr) |
31 | { |
32 | if (ptr != NULL) |
33 | free(ptr); |
34 | } |
35 | |
36 | void *pfs_malloc_array(size_t n, size_t size, myf flags) |
37 | { |
38 | size_t array_size= n * size; |
39 | /* Check for overflow before allocating. */ |
40 | if (is_overflow(array_size, n, size)) |
41 | return NULL; |
42 | return pfs_malloc(array_size, flags); |
43 | } |
44 | |
45 | bool is_overflow(size_t product, size_t n1, size_t n2) |
46 | { |
47 | if (n1 != 0 && (product / n1 != n2)) |
48 | return true; |
49 | else |
50 | return false; |
51 | } |
52 | |
53 | void pfs_print_error(const char *format, ...) |
54 | { |
55 | /* Do not pollute the unit test output with annoying messages. */ |
56 | } |
57 | |
58 | |