mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-26 08:50:37 +02:00
eeshow/misc/util.h (realloc_size, realloc_type_n): get rid of bare "realloc"
Finally ! Shoulds have done this a long time ago.
This commit is contained in:
parent
1b250bd467
commit
465a36fde5
@ -46,10 +46,8 @@ static struct hist *new_commit(unsigned branch)
|
|||||||
|
|
||||||
static void uplink(struct hist *down, struct hist *up)
|
static void uplink(struct hist *down, struct hist *up)
|
||||||
{
|
{
|
||||||
down->newer = realloc(down->newer,
|
down->newer = realloc_type_n(down->newer, struct hist *,
|
||||||
sizeof(struct hist *) * (down->n_newer + 1));
|
down->n_newer + 1);
|
||||||
if (!down->newer)
|
|
||||||
diag_pfatal("realloc");
|
|
||||||
down->newer[down->n_newer++] = up;
|
down->newer[down->n_newer++] = up;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -404,9 +404,7 @@ static void cr_pdf_new_sheet(void *ctx)
|
|||||||
struct cro_ctx *cc = ctx;
|
struct cro_ctx *cc = ctx;
|
||||||
|
|
||||||
cc->n_sheets++;
|
cc->n_sheets++;
|
||||||
cc->sheets = realloc(cc->sheets, sizeof(struct record) * cc->n_sheets);
|
cc->sheets = realloc_type_n(cc->sheets, struct record, cc->n_sheets);
|
||||||
if (!cc->sheets)
|
|
||||||
diag_pfatal("realloc");
|
|
||||||
cc->sheets[cc->n_sheets - 1] = cc->record;
|
cc->sheets[cc->n_sheets - 1] = cc->record;
|
||||||
record_wipe(&cc->record);
|
record_wipe(&cc->record);
|
||||||
}
|
}
|
||||||
|
@ -262,7 +262,7 @@ static void *fig_init(int argc, char *const *argv)
|
|||||||
if (!strchr(argv[arg], '='))
|
if (!strchr(argv[arg], '='))
|
||||||
usage(*argv);
|
usage(*argv);
|
||||||
n_vars++;
|
n_vars++;
|
||||||
vars = realloc(vars, sizeof(const char *) * n_vars);
|
vars = realloc_type_n(vars, const char *, n_vars);
|
||||||
vars[n_vars - 1] = argv[arg];
|
vars[n_vars - 1] = argv[arg];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,8 +114,7 @@ static void add_object(struct pdftoc *ctx, int id, int gen, unsigned pos)
|
|||||||
struct object *obj;
|
struct object *obj;
|
||||||
|
|
||||||
if (id > ctx->top) {
|
if (id > ctx->top) {
|
||||||
ctx->objs = realloc(ctx->objs,
|
ctx->objs = realloc_type_n(ctx->objs, struct object, id + 1);
|
||||||
(id + 1) * sizeof(struct object));
|
|
||||||
memset(ctx->objs + ctx->top + 1 , 0,
|
memset(ctx->objs + ctx->top + 1 , 0,
|
||||||
(id - ctx->top) * sizeof(struct object));
|
(id - ctx->top) * sizeof(struct object));
|
||||||
ctx->top = id;
|
ctx->top = id;
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "misc/util.h"
|
||||||
#include "misc/diag.h"
|
#include "misc/diag.h"
|
||||||
#include "kicad/ext.h"
|
#include "kicad/ext.h"
|
||||||
|
|
||||||
@ -68,10 +69,8 @@ void classify_files(struct file_names *fn, char *const *args,
|
|||||||
break;
|
break;
|
||||||
case ext_lib:
|
case ext_lib:
|
||||||
fn->n_libs++;
|
fn->n_libs++;
|
||||||
fn->libs = realloc(fn->libs,
|
fn->libs = realloc_type_n(fn->libs, const char *,
|
||||||
fn->n_libs * sizeof(const char *));
|
fn->n_libs);
|
||||||
if (!fn->libs)
|
|
||||||
diag_pfatal("realloc");
|
|
||||||
fn->libs[fn->n_libs - 1] = args[i];
|
fn->libs[fn->n_libs - 1] = args[i];
|
||||||
break;
|
break;
|
||||||
case ext_pl:
|
case ext_pl:
|
||||||
|
@ -109,9 +109,7 @@ static char *expand(const struct pl_ctx *pl, const char *s,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
len = strlen(x);
|
len = strlen(x);
|
||||||
res = realloc(res, size + p - s + len);
|
res = realloc_size(res, size + p - s + len);
|
||||||
if (!res)
|
|
||||||
diag_pfatal("realloc");
|
|
||||||
memcpy(res + size, s, p - s);
|
memcpy(res + size, s, p - s);
|
||||||
size += p - s;
|
size += p - s;
|
||||||
s = p + 2;
|
s = p + 2;
|
||||||
@ -120,9 +118,7 @@ static char *expand(const struct pl_ctx *pl, const char *s,
|
|||||||
}
|
}
|
||||||
|
|
||||||
len = strlen(s);
|
len = strlen(s);
|
||||||
res = realloc(res, size + len + 1);
|
res = realloc_size(res, size + len + 1);
|
||||||
if (!res)
|
|
||||||
diag_pfatal("realloc");
|
|
||||||
memcpy(res + size, s, len + 1);
|
memcpy(res + size, s, len + 1);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@ -134,9 +130,7 @@ static char *increment(char *s, int inc, const char *range)
|
|||||||
unsigned len = strlen(s);
|
unsigned len = strlen(s);
|
||||||
int base, n;
|
int base, n;
|
||||||
|
|
||||||
t = realloc(s, len + 2);
|
t = realloc_size(s, len + 2);
|
||||||
if (!t)
|
|
||||||
diag_perror("realloc");
|
|
||||||
t[len + 1] = 0;
|
t[len + 1] = 0;
|
||||||
|
|
||||||
base = range[1] - range[0] + 1;
|
base = range[1] - range[0] + 1;
|
||||||
|
@ -149,9 +149,7 @@ static bool parse_field(struct sch_ctx *ctx, const char *line)
|
|||||||
|
|
||||||
if (n == 0 && comp->comp && comp->comp->units > 1) {
|
if (n == 0 && comp->comp && comp->comp->units > 1) {
|
||||||
len = strlen(txt->s);
|
len = strlen(txt->s);
|
||||||
s = realloc((void *) txt->s, len + 3);
|
s = realloc_size((void *) txt->s, len + 3);
|
||||||
if (!s)
|
|
||||||
diag_pfatal("realloc");
|
|
||||||
if (comp->unit <= 26)
|
if (comp->unit <= 26)
|
||||||
sprintf(s + len, "%c", 'A' + comp->unit - 1);
|
sprintf(s + len, "%c", 'A' + comp->unit - 1);
|
||||||
else
|
else
|
||||||
|
@ -83,9 +83,7 @@ static void add_string(struct sexpr_ctx *ctx, const char *end)
|
|||||||
if (!new)
|
if (!new)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
e->s = realloc(e->s, old + new + 1);
|
e->s = realloc_size(e->s, old + new + 1);
|
||||||
if (!e->s)
|
|
||||||
diag_pfatal("realloc");
|
|
||||||
memcpy(e->s + old, ctx->p, new);
|
memcpy(e->s + old, ctx->p, new);
|
||||||
e->s[old + new] = 0;
|
e->s[old + new] = 0;
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,18 @@
|
|||||||
#define alloc_type(t) ((t *) alloc_size(sizeof(t)))
|
#define alloc_type(t) ((t *) alloc_size(sizeof(t)))
|
||||||
#define alloc_type_n(t, n) ((t *) alloc_size(sizeof(t) * (n)))
|
#define alloc_type_n(t, n) ((t *) alloc_size(sizeof(t) * (n)))
|
||||||
|
|
||||||
|
|
||||||
|
#define realloc_size(p, s) \
|
||||||
|
({ void *alloc_size_tmp = realloc((p), (s)); \
|
||||||
|
if (!alloc_size_tmp) { \
|
||||||
|
perror("realloc"); \
|
||||||
|
exit(1); \
|
||||||
|
} \
|
||||||
|
alloc_size_tmp; })
|
||||||
|
|
||||||
|
#define realloc_type_n(p, t, n) ((t *) realloc_size((p), sizeof(t) * (n)))
|
||||||
|
|
||||||
|
|
||||||
#define stralloc(s) \
|
#define stralloc(s) \
|
||||||
({ char *stralloc_tmp = strdup(s); \
|
({ char *stralloc_tmp = strdup(s); \
|
||||||
if (!stralloc_tmp) { \
|
if (!stralloc_tmp) { \
|
||||||
|
Loading…
Reference in New Issue
Block a user