diff options
author | Hartmut Knaack <knaack.h@gmx.de> | 2015-05-31 14:40:02 +0200 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2015-05-31 19:21:10 +0100 |
commit | e9e45b43b8f06273d9b78f187042dff0bf5be0a5 (patch) | |
tree | 2e0bb238e6b234a12366c545e879b9b6646b9985 /tools/iio/iio_utils.c | |
parent | 2156b179993e3d5b422976181ba17d91153313e1 (diff) |
tools:iio: catch errors in string allocation
This patch catches errors in string allocation in generic_buffer.c,
iio_event_monitor.c, iio_utils.c and lsiio.c.
Signed-off-by: Hartmut Knaack <knaack.h@gmx.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'tools/iio/iio_utils.c')
-rw-r--r-- | tools/iio/iio_utils.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/tools/iio/iio_utils.c b/tools/iio/iio_utils.c index 812153ff18c3..f0896f46847f 100644 --- a/tools/iio/iio_utils.c +++ b/tools/iio/iio_utils.c @@ -36,7 +36,7 @@ int iioutils_break_up_name(const char *full_name, char *current; char *w, *r; char *working, *prefix = ""; - int i; + int i, ret; for (i = 0; i < sizeof(iio_direction) / sizeof(iio_direction[0]); i++) if (!strncmp(full_name, iio_direction[i], @@ -46,6 +46,9 @@ int iioutils_break_up_name(const char *full_name, } current = strdup(full_name + strlen(prefix) + 1); + if (!current) + return -ENOMEM; + working = strtok(current, "_\0"); w = working; @@ -59,10 +62,10 @@ int iioutils_break_up_name(const char *full_name, r++; } *w = '\0'; - asprintf(generic_name, "%s_%s", prefix, working); + ret = asprintf(generic_name, "%s_%s", prefix, working); free(current); - return 0; + return (ret == -1) ? -ENOMEM : 0; } /** |