aboutsummaryrefslogtreecommitdiffstats
path: root/strndup.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 /strndup.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 '')
-rw-r--r--strndup.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/strndup.c b/strndup.c
index faa3bb1..d4c681f 100644
--- a/strndup.c
+++ b/strndup.c
@@ -13,7 +13,7 @@ libsimple_strndup(const char *s, size_t n)
errno = ENOMEM;
return NULL;
}
- if (!(ret = malloc(n + 1)))
+ if (!(ret = aligned_alloc(1, n + 1)))
return NULL;
memcpy(ret, s, n);
ret[n] = '\0';
@@ -27,6 +27,7 @@ libsimple_strndup(const char *s, size_t n)
int
main(void)
{
+ struct allocinfo *info;
const char *s = "test";
void *p;
@@ -35,6 +36,10 @@ main(void)
assert(!strcmpnul(p, "test"));
memset(p, 0, 5);
assert(!strcmpnul(s, "test"));
+ if (have_custom_malloc()) {
+ assert((info = get_allocinfo(p)));
+ assert(info->alignment == 1);
+ }
free(p);
p = libsimple_strndup(s, 3);
@@ -42,6 +47,10 @@ main(void)
assert(!strcmpnul(p, "tes"));
memset(p, 0, 4);
assert(!strcmpnul(s, "test"));
+ if (have_custom_malloc()) {
+ assert((info = get_allocinfo(p)));
+ assert(info->alignment == 1);
+ }
free(p);
p = libsimple_strndup(s, 0);
@@ -49,6 +58,10 @@ main(void)
assert(!strcmpnul(p, ""));
memset(p, 0, 1);
assert(!strcmpnul(s, "test"));
+ if (have_custom_malloc()) {
+ assert((info = get_allocinfo(p)));
+ assert(info->alignment == 1);
+ }
free(p);
return 0;