Date: | 2016-08-23 02:00:10 (7 years 3 months ago) |
---|---|
Author: | Werner Almesberger |
Commit: | 465a36fde541da7679fc90b3cfc55721f6d899ba |
Message: | eeshow/misc/util.h (realloc_size, realloc_type_n): get rid of bare
"realloc" Finally ! Shoulds have done this a long time ago. |
Files: |
eeshow/file/git-hist.c (1 diff) eeshow/gfx/cro.c (1 diff) eeshow/gfx/fig.c (1 diff) eeshow/gfx/pdftoc.c (1 diff) eeshow/kicad/ext.c (2 diffs) eeshow/kicad/pl-render.c (3 diffs) eeshow/kicad/sch-parse.c (1 diff) eeshow/kicad/sexpr.c (1 diff) eeshow/misc/util.h (1 diff) |
Change Details
eeshow/file/git-hist.c | ||
---|---|---|
46 | 46 | |
47 | 47 | static void uplink(struct hist *down, struct hist *up) |
48 | 48 | { |
49 | down->newer = realloc(down->newer, | |
50 | sizeof(struct hist *) * (down->n_newer + 1)); | |
51 | if (!down->newer) | |
52 | diag_pfatal("realloc"); | |
49 | down->newer = realloc_type_n(down->newer, struct hist *, | |
50 | down->n_newer + 1); | |
53 | 51 | down->newer[down->n_newer++] = up; |
54 | 52 | } |
55 | 53 |
eeshow/gfx/cro.c | ||
---|---|---|
404 | 404 | struct cro_ctx *cc = ctx; |
405 | 405 | |
406 | 406 | cc->n_sheets++; |
407 | cc->sheets = realloc(cc->sheets, sizeof(struct record) * cc->n_sheets); | |
408 | if (!cc->sheets) | |
409 | diag_pfatal("realloc"); | |
407 | cc->sheets = realloc_type_n(cc->sheets, struct record, cc->n_sheets); | |
410 | 408 | cc->sheets[cc->n_sheets - 1] = cc->record; |
411 | 409 | record_wipe(&cc->record); |
412 | 410 | } |
eeshow/gfx/fig.c | ||
---|---|---|
262 | 262 | if (!strchr(argv[arg], '=')) |
263 | 263 | usage(*argv); |
264 | 264 | n_vars++; |
265 | vars = realloc(vars, sizeof(const char *) * n_vars); | |
265 | vars = realloc_type_n(vars, const char *, n_vars); | |
266 | 266 | vars[n_vars - 1] = argv[arg]; |
267 | 267 | } |
268 | 268 |
eeshow/gfx/pdftoc.c | ||
---|---|---|
114 | 114 | struct object *obj; |
115 | 115 | |
116 | 116 | if (id > ctx->top) { |
117 | ctx->objs = realloc(ctx->objs, | |
118 | (id + 1) * sizeof(struct object)); | |
117 | ctx->objs = realloc_type_n(ctx->objs, struct object, id + 1); | |
119 | 118 | memset(ctx->objs + ctx->top + 1 , 0, |
120 | 119 | (id - ctx->top) * sizeof(struct object)); |
121 | 120 | ctx->top = id; |
eeshow/kicad/ext.c | ||
---|---|---|
13 | 13 | #include <stdlib.h> |
14 | 14 | #include <string.h> |
15 | 15 | |
16 | #include "misc/util.h" | |
16 | 17 | #include "misc/diag.h" |
17 | 18 | #include "kicad/ext.h" |
18 | 19 | |
... | ... | |
68 | 69 | break; |
69 | 70 | case ext_lib: |
70 | 71 | fn->n_libs++; |
71 | fn->libs = realloc(fn->libs, | |
72 | fn->n_libs * sizeof(const char *)); | |
73 | if (!fn->libs) | |
74 | diag_pfatal("realloc"); | |
72 | fn->libs = realloc_type_n(fn->libs, const char *, | |
73 | fn->n_libs); | |
75 | 74 | fn->libs[fn->n_libs - 1] = args[i]; |
76 | 75 | break; |
77 | 76 | case ext_pl: |
eeshow/kicad/pl-render.c | ||
---|---|---|
109 | 109 | break; |
110 | 110 | } |
111 | 111 | len = strlen(x); |
112 | res = realloc(res, size + p - s + len); | |
113 | if (!res) | |
114 | diag_pfatal("realloc"); | |
112 | res = realloc_size(res, size + p - s + len); | |
115 | 113 | memcpy(res + size, s, p - s); |
116 | 114 | size += p - s; |
117 | 115 | s = p + 2; |
... | ... | |
120 | 118 | } |
121 | 119 | |
122 | 120 | len = strlen(s); |
123 | res = realloc(res, size + len + 1); | |
124 | if (!res) | |
125 | diag_pfatal("realloc"); | |
121 | res = realloc_size(res, size + len + 1); | |
126 | 122 | memcpy(res + size, s, len + 1); |
127 | 123 | return res; |
128 | 124 | } |
... | ... | |
134 | 130 | unsigned len = strlen(s); |
135 | 131 | int base, n; |
136 | 132 | |
137 | t = realloc(s, len + 2); | |
138 | if (!t) | |
139 | diag_perror("realloc"); | |
133 | t = realloc_size(s, len + 2); | |
140 | 134 | t[len + 1] = 0; |
141 | 135 | |
142 | 136 | base = range[1] - range[0] + 1; |
eeshow/kicad/sch-parse.c | ||
---|---|---|
149 | 149 | |
150 | 150 | if (n == 0 && comp->comp && comp->comp->units > 1) { |
151 | 151 | len = strlen(txt->s); |
152 | s = realloc((void *) txt->s, len + 3); | |
153 | if (!s) | |
154 | diag_pfatal("realloc"); | |
152 | s = realloc_size((void *) txt->s, len + 3); | |
155 | 153 | if (comp->unit <= 26) |
156 | 154 | sprintf(s + len, "%c", 'A' + comp->unit - 1); |
157 | 155 | else |
eeshow/kicad/sexpr.c | ||
---|---|---|
83 | 83 | if (!new) |
84 | 84 | return; |
85 | 85 | |
86 | e->s = realloc(e->s, old + new + 1); | |
87 | if (!e->s) | |
88 | diag_pfatal("realloc"); | |
86 | e->s = realloc_size(e->s, old + new + 1); | |
89 | 87 | memcpy(e->s + old, ctx->p, new); |
90 | 88 | e->s[old + new] = 0; |
91 | 89 | } |
eeshow/misc/util.h | ||
---|---|---|
30 | 30 | #define alloc_type(t) ((t *) alloc_size(sizeof(t))) |
31 | 31 | #define alloc_type_n(t, n) ((t *) alloc_size(sizeof(t) * (n))) |
32 | 32 | |
33 | ||
34 | #define realloc_size(p, s) \ | |
35 | ({ void *alloc_size_tmp = realloc((p), (s)); \ | |
36 | if (!alloc_size_tmp) { \ | |
37 | perror("realloc"); \ | |
38 | exit(1); \ | |
39 | } \ | |
40 | alloc_size_tmp; }) | |
41 | ||
42 | #define realloc_type_n(p, t, n) ((t *) realloc_size((p), sizeof(t) * (n))) | |
43 | ||
44 | ||
33 | 45 | #define stralloc(s) \ |
34 | 46 | ({ char *stralloc_tmp = strdup(s); \ |
35 | 47 | if (!stralloc_tmp) { \ |
Branches:
master