From b8b8b6b70e670cb735b43bc6b90150ab1ed4e2d1 Mon Sep 17 00:00:00 2001 From: overcaffeinated Date: Thu, 27 Oct 2016 10:12:28 +0100 Subject: [PATCH] Add implementation of smartlist_add_strdup Add smartlist_add_strdup(sl, string) - replaces the use of smartlist_add(sl, tor_strdup(string)). Fixes bug 20048. --- changes/bug20048 | 4 ++++ src/common/util.c | 11 +++++++++++ src/common/util.h | 1 + 3 files changed, 16 insertions(+) create mode 100644 changes/bug20048 diff --git a/changes/bug20048 b/changes/bug20048 new file mode 100644 index 0000000000..0874e97e7a --- /dev/null +++ b/changes/bug20048 @@ -0,0 +1,4 @@ + o Minor bugfixes: + - Implement smartlist_add_strdup() function. Replaces the use of + smartlist_add(sl, tor_strdup(str)). Fixes bug 20048. + diff --git a/src/common/util.c b/src/common/util.c index 9162967907..02ccf4ff0f 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -3532,6 +3532,17 @@ smartlist_add_vasprintf(struct smartlist_t *sl, const char *pattern, smartlist_add(sl, str); } +/** Append a copy of string to sl */ +void +smartlist_add_strdup(struct smartlist_t *sl, const char *string) +{ + char *copy; + + copy = tor_strdup(string); + + smartlist_add(sl, copy); +} + /** Return a new list containing the filenames in the directory dirname. * Return NULL on error or if dirname is not a directory. */ diff --git a/src/common/util.h b/src/common/util.h index 479fc8d610..37f4bed1cb 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -239,6 +239,7 @@ void smartlist_add_asprintf(struct smartlist_t *sl, const char *pattern, ...) void smartlist_add_vasprintf(struct smartlist_t *sl, const char *pattern, va_list args) CHECK_PRINTF(2, 0); +void smartlist_add_strdup(struct smartlist_t *sl, const char *string); /* Time helpers */ long tv_udiff(const struct timeval *start, const struct timeval *end);