diff options
author | Stef Walter <stefw@gnome.org> | 2013-03-20 20:59:26 +0100 |
---|---|---|
committer | Stef Walter <stefw@gnome.org> | 2013-03-20 22:22:22 +0100 |
commit | 57d8f36a6cfbde5a9a783f11f2b75f19005c23e1 (patch) | |
tree | d21f862a9698ef6066ce2b14ef82fbd8c370f9ac /common/compat.c | |
parent | 9cf89e4b43e5e018bb3103be1873a3993769ce4a (diff) | |
download | p11-kit-57d8f36a6cfbde5a9a783f11f2b75f19005c23e1.tar.gz |
Fix invalid memory accesses reported by 'make memcheck'
These are things that showed up in valgrind while running the tests.
Diffstat (limited to 'common/compat.c')
-rw-r--r-- | common/compat.c | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/common/compat.c b/common/compat.c index 2548459..2cda460 100644 --- a/common/compat.c +++ b/common/compat.c @@ -459,15 +459,12 @@ strndup (const char *data, size_t length) { char *ret; - size_t len; - - len = strlen (data); - if (length > len) - length = len; - ret = memdup (data, length + 1); - if (ret != NULL) + ret = malloc (length + 1); + if (ret != NULL) { + strncpy (ret, data, length); ret[length] = 0; + } return ret; } |