summaryrefslogtreecommitdiff
path: root/lib/xmemdup0.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/xmemdup0.c')
-rw-r--r--lib/xmemdup0.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/xmemdup0.c b/lib/xmemdup0.c
index 1b53d11..57c1b59 100644
--- a/lib/xmemdup0.c
+++ b/lib/xmemdup0.c
@@ -1,6 +1,6 @@
/* xmemdup0.c -- copy a block of arbitrary bytes, plus a trailing NUL
- Copyright (C) 2008-2018 Free Software Foundation, Inc.
+ Copyright (C) 2008-2019 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -38,7 +38,8 @@ char *
xmemdup0 (void const *p, size_t s)
{
char *result = xcharalloc (s + 1);
- memcpy (result, p, s);
+ if (s > 0)
+ memcpy (result, p, s);
result[s] = 0;
return result;
}