Print this page
Address Robert's feedback
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libsysdemangle/common/util.c
+++ new/usr/src/lib/libsysdemangle/common/util.c
1 1 /*
2 2 * This file and its contents are supplied under the terms of the
3 3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 4 * You may only use this file in accordance with the terms of version
5 5 * 1.0 of the CDDL.
6 6 *
7 7 * A full copy of the text of the CDDL should have accompanied this
8 8 * source. A copy of the CDDL is also available via the Internet at
9 9 * http://www.illumos.org/license/CDDL.
10 10 */
11 11
12 12 /*
13 13 * Copyright 2017 Jason King
14 14 */
15 15
16 16 #include <sys/debug.h>
17 17 #include <stdlib.h>
18 18 #include <string.h>
19 19 #include "sysdemangle.h"
20 20 #include "sysdemangle_int.h"
21 21
22 22 void *
23 23 zalloc(sysdem_ops_t *ops, size_t len)
24 24 {
25 25 void *p = ops->alloc(len);
26 26
27 27 if (p != NULL)
28 28 (void) memset(p, 0, len);
29 29
30 30 #ifdef DEBUG
31 31 /*
32 32 * In normal operation, we should never exhaust memory. Either
33 33 * something's wrong, or the system is so hosed that aborting
34 34 * shouldn't hurt anything, and it gives us a more useful stack
35 35 * trace.
36 36 */
37 37 if (p == NULL)
38 38 abort();
39 39 #endif
40 40
41 41 return (p);
42 42 }
43 43
44 44 void
45 45 xfree(sysdem_ops_t *ops, void *p, size_t len)
46 46 {
47 47 if (p == NULL || len == 0)
48 48 return;
↓ open down ↓ |
48 lines elided |
↑ open up ↑ |
49 49
50 50 ops->free(p, len);
51 51 }
52 52
53 53 void *
54 54 xrealloc(sysdem_ops_t *ops, void *p, size_t oldsz, size_t newsz)
55 55 {
56 56 if (newsz == oldsz)
57 57 return (p);
58 58
59 - ASSERT3U(newsz, >, oldsz);
59 + VERIFY3U(newsz, >, oldsz);
60 60
61 61 void *temp = zalloc(ops, newsz);
62 62
63 63 if (temp == NULL)
64 64 return (NULL);
65 65
66 66 if (oldsz > 0) {
67 67 (void) memcpy(temp, p, oldsz);
68 68 xfree(ops, p, oldsz);
69 69 }
70 70
↓ open down ↓ |
1 lines elided |
↑ open up ↑ |
71 71 return (temp);
72 72 }
73 73
74 74 /*ARGSUSED*/
75 75 static void
76 76 def_free(void *p, size_t len)
77 77 {
78 78 free(p);
79 79 }
80 80
81 -/* BEGIN CSTYLED */
82 -sysdem_ops_t *sysdem_ops_default = &(sysdem_ops_t){
81 +static sysdem_ops_t i_sysdem_ops_default = {
83 82 .alloc = malloc,
84 83 .free = def_free
85 84 };
86 -/* END CSTYLED */
85 +sysdem_ops_t *sysdem_ops_default = &i_sysdem_ops_default;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX