summaryrefslogtreecommitdiff
path: root/kicad
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-08-22 21:00:10 -0300
committerWerner Almesberger <werner@almesberger.net>2016-08-22 21:00:40 -0300
commitce690a463d1905b2aba8a04c29a248af66153681 (patch)
tree96072589d04ca8b1c536c6a0b5c8f58c7c2a21b1 /kicad
parent8dfb6b2c9f722d70b30e5794fe20ce9450dd05d4 (diff)
downloadeeshow-ce690a463d1905b2aba8a04c29a248af66153681.tar.gz
eeshow-ce690a463d1905b2aba8a04c29a248af66153681.tar.bz2
eeshow-ce690a463d1905b2aba8a04c29a248af66153681.zip
eeshow/misc/util.h (realloc_size, realloc_type_n): get rid of bare "realloc"
Finally ! Shoulds have done this a long time ago.
Diffstat (limited to 'kicad')
-rw-r--r--kicad/ext.c7
-rw-r--r--kicad/pl-render.c12
-rw-r--r--kicad/sch-parse.c4
-rw-r--r--kicad/sexpr.c4
4 files changed, 8 insertions, 19 deletions
diff --git a/kicad/ext.c b/kicad/ext.c
index 961f231..15d4e75 100644
--- a/kicad/ext.c
+++ b/kicad/ext.c
@@ -13,6 +13,7 @@
#include <stdlib.h>
#include <string.h>
+#include "misc/util.h"
#include "misc/diag.h"
#include "kicad/ext.h"
@@ -68,10 +69,8 @@ void classify_files(struct file_names *fn, char *const *args,
break;
case ext_lib:
fn->n_libs++;
- fn->libs = realloc(fn->libs,
- fn->n_libs * sizeof(const char *));
- if (!fn->libs)
- diag_pfatal("realloc");
+ fn->libs = realloc_type_n(fn->libs, const char *,
+ fn->n_libs);
fn->libs[fn->n_libs - 1] = args[i];
break;
case ext_pl:
diff --git a/kicad/pl-render.c b/kicad/pl-render.c
index c3cea2a..386f719 100644
--- a/kicad/pl-render.c
+++ b/kicad/pl-render.c
@@ -109,9 +109,7 @@ static char *expand(const struct pl_ctx *pl, const char *s,
break;
}
len = strlen(x);
- res = realloc(res, size + p - s + len);
- if (!res)
- diag_pfatal("realloc");
+ res = realloc_size(res, size + p - s + len);
memcpy(res + size, s, p - s);
size += p - s;
s = p + 2;
@@ -120,9 +118,7 @@ static char *expand(const struct pl_ctx *pl, const char *s,
}
len = strlen(s);
- res = realloc(res, size + len + 1);
- if (!res)
- diag_pfatal("realloc");
+ res = realloc_size(res, size + len + 1);
memcpy(res + size, s, len + 1);
return res;
}
@@ -134,9 +130,7 @@ static char *increment(char *s, int inc, const char *range)
unsigned len = strlen(s);
int base, n;
- t = realloc(s, len + 2);
- if (!t)
- diag_perror("realloc");
+ t = realloc_size(s, len + 2);
t[len + 1] = 0;
base = range[1] - range[0] + 1;
diff --git a/kicad/sch-parse.c b/kicad/sch-parse.c
index 9cc3bbd..456ad13 100644
--- a/kicad/sch-parse.c
+++ b/kicad/sch-parse.c
@@ -149,9 +149,7 @@ static bool parse_field(struct sch_ctx *ctx, const char *line)
if (n == 0 && comp->comp && comp->comp->units > 1) {
len = strlen(txt->s);
- s = realloc((void *) txt->s, len + 3);
- if (!s)
- diag_pfatal("realloc");
+ s = realloc_size((void *) txt->s, len + 3);
if (comp->unit <= 26)
sprintf(s + len, "%c", 'A' + comp->unit - 1);
else
diff --git a/kicad/sexpr.c b/kicad/sexpr.c
index 0727891..6f0fd2f 100644
--- a/kicad/sexpr.c
+++ b/kicad/sexpr.c
@@ -83,9 +83,7 @@ static void add_string(struct sexpr_ctx *ctx, const char *end)
if (!new)
return;
- e->s = realloc(e->s, old + new + 1);
- if (!e->s)
- diag_pfatal("realloc");
+ e->s = realloc_size(e->s, old + new + 1);
memcpy(e->s + old, ctx->p, new);
e->s[old + new] = 0;
}