aboutsummaryrefslogtreecommitdiff
path: root/src/core/options.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-08-25 11:11:35 -0700
committerGarrett D'Amore <garrett@damore.org>2017-08-28 11:39:03 -0700
commit601c64ec4f2b8a41fba59d31a987090feeb69e84 (patch)
tree985ec57b3e238b4eed9b42ddaa4736b949df8c6f /src/core/options.c
parent595da8102f3e34e95dad351bc55cd45421616723 (diff)
downloadnng-601c64ec4f2b8a41fba59d31a987090feeb69e84.tar.gz
nng-601c64ec4f2b8a41fba59d31a987090feeb69e84.tar.bz2
nng-601c64ec4f2b8a41fba59d31a987090feeb69e84.zip
Introduce utility safe string handling functions.
We have our versions of strdup, strlcat, and strlcpy. This means we can avoid using snprintf() in many cases (saving cycles), and we can get safer checks. We use the platform supplied versions of these if they exist (wrapping with nni_xxx versions.)
Diffstat (limited to 'src/core/options.c')
-rw-r--r--src/core/options.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/src/core/options.c b/src/core/options.c
index 03002d6c..4027564c 100644
--- a/src/core/options.c
+++ b/src/core/options.c
@@ -275,13 +275,11 @@ nni_option_set_id(const char *name, int id)
nni_mtx_unlock(&nni_option_lk);
return (NNG_ENOMEM);
}
- len = strlen(name) + 1;
- if ((opt->o_name = nni_alloc(len)) == NULL) {
+ if ((opt->o_name = nni_strdup(name)) == NULL) {
nni_mtx_unlock(&nni_option_lk);
NNI_FREE_STRUCT(opt);
return (NNG_ENOMEM);
}
- (void) snprintf(opt->o_name, len, "%s", name);
if (id < 0) {
id = nni_option_nextid++;
}
@@ -347,7 +345,7 @@ nni_option_sys_fini(void)
nni_option *opt;
while ((opt = nni_list_first(&nni_options)) != NULL) {
nni_list_remove(&nni_options, opt);
- nni_free(opt->o_name, strlen(opt->o_name) + 1);
+ nni_strfree(opt->o_name);
NNI_FREE_STRUCT(opt);
}
}