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
4646
4747static void uplink(struct hist *down, struct hist *up)
4848{
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);
5351    down->newer[down->n_newer++] = up;
5452}
5553
eeshow/gfx/cro.c
404404    struct cro_ctx *cc = ctx;
405405
406406    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);
410408    cc->sheets[cc->n_sheets - 1] = cc->record;
411409    record_wipe(&cc->record);
412410}
eeshow/gfx/fig.c
262262        if (!strchr(argv[arg], '='))
263263            usage(*argv);
264264        n_vars++;
265        vars = realloc(vars, sizeof(const char *) * n_vars);
265        vars = realloc_type_n(vars, const char *, n_vars);
266266        vars[n_vars - 1] = argv[arg];
267267    }
268268
eeshow/gfx/pdftoc.c
114114    struct object *obj;
115115
116116    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);
119118        memset(ctx->objs + ctx->top + 1 , 0,
120119            (id - ctx->top) * sizeof(struct object));
121120        ctx->top = id;
eeshow/kicad/ext.c
1313#include <stdlib.h>
1414#include <string.h>
1515
16#include "misc/util.h"
1617#include "misc/diag.h"
1718#include "kicad/ext.h"
1819
...... 
6869            break;
6970        case ext_lib:
7071            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);
7574            fn->libs[fn->n_libs - 1] = args[i];
7675            break;
7776        case ext_pl:
eeshow/kicad/pl-render.c
109109            break;
110110        }
111111        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);
115113        memcpy(res + size, s, p - s);
116114        size += p - s;
117115        s = p + 2;
...... 
120118    }
121119
122120    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);
126122    memcpy(res + size, s, len + 1);
127123    return res;
128124}
...... 
134130    unsigned len = strlen(s);
135131    int base, n;
136132
137    t = realloc(s, len + 2);
138    if (!t)
139        diag_perror("realloc");
133    t = realloc_size(s, len + 2);
140134    t[len + 1] = 0;
141135
142136    base = range[1] - range[0] + 1;
eeshow/kicad/sch-parse.c
149149
150150    if (n == 0 && comp->comp && comp->comp->units > 1) {
151151        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);
155153        if (comp->unit <= 26)
156154            sprintf(s + len, "%c", 'A' + comp->unit - 1);
157155        else
eeshow/kicad/sexpr.c
8383    if (!new)
8484        return;
8585
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);
8987    memcpy(e->s + old, ctx->p, new);
9088    e->s[old + new] = 0;
9189}
eeshow/misc/util.h
3030#define alloc_type(t) ((t *) alloc_size(sizeof(t)))
3131#define alloc_type_n(t, n) ((t *) alloc_size(sizeof(t) * (n)))
3232
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
3345#define stralloc(s) \
3446    ({ char *stralloc_tmp = strdup(s); \
3547    if (!stralloc_tmp) { \

Archive Download the corresponding diff file

Branches:
master



interactive