aboutsummaryrefslogtreecommitdiffstats
path: root/enstrdup.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2018-09-02 15:32:56 +0200
committerMattias Andrée <maandree@kth.se>2018-09-02 15:32:56 +0200
commit47128b7def4954c4cf544924c94f018d88033374 (patch)
treec75e6c76c078a095ff691d42a1f0b2d0ea0f0357 /enstrdup.c
parentAdd malloc function attribute were appropriate (diff)
downloadlibsimple-47128b7def4954c4cf544924c94f018d88033374.tar.gz
libsimple-47128b7def4954c4cf544924c94f018d88033374.tar.bz2
libsimple-47128b7def4954c4cf544924c94f018d88033374.tar.xz
misc
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'enstrdup.c')
-rw-r--r--enstrdup.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/enstrdup.c b/enstrdup.c
index 4ad78d4..f330422 100644
--- a/enstrdup.c
+++ b/enstrdup.c
@@ -6,9 +6,11 @@
char *
libsimple_enstrdup(int status, const char *s)
{
- char *ret = strdup(s);
+ size_t n = strlen(s) + 1;
+ char *ret = aligned_alloc(1, n);
if (!ret)
enprintf(status, "strdup:");
+ memcpy(ret, s, n);
return ret;
}
@@ -26,6 +28,7 @@ main(void)
if (have_custom_malloc()) {
assert((info = get_allocinfo(s)));
assert(info->size == 6);
+ assert(info->alignment == 1);
assert(!info->zeroed);
}
assert(!strcmp(s, "hello"));
@@ -35,6 +38,7 @@ main(void)
if (have_custom_malloc()) {
assert((info = get_allocinfo(s)));
assert(info->size == 5);
+ assert(info->alignment == 1);
assert(!info->zeroed);
}
assert(!strcmp(s, "test"));