aboutsummaryrefslogtreecommitdiffstats
path: root/wpa_supplicant/wpa_cli.c
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2013-04-27 20:44:59 (GMT)
committerJouni Malinen <j@w1.fi>2013-04-27 20:44:59 (GMT)
commit5e24dc8a4bc8297dee3b95594457a51d36fde00d (patch)
tree4a97b61e2333269d577fee2187ea03c4dec603d1 /wpa_supplicant/wpa_cli.c
parent8b44ad7e162203db56056503d806246ee6a2ad0f (diff)
downloadhostap-5e24dc8a4bc8297dee3b95594457a51d36fde00d.zip
hostap-5e24dc8a4bc8297dee3b95594457a51d36fde00d.tar.gz
hostap-5e24dc8a4bc8297dee3b95594457a51d36fde00d.tar.bz2
Add dup_binstr() to help common binary string tasks
There are quite a few places in the current implementation where a nul terminated string is generated from binary data. Add a helper function to simplify the code a bit. Signed-hostap: Jouni Malinen <j@w1.fi>
Diffstat (limited to 'wpa_supplicant/wpa_cli.c')
-rw-r--r--wpa_supplicant/wpa_cli.c8
1 files changed, 2 insertions, 6 deletions
diff --git a/wpa_supplicant/wpa_cli.c b/wpa_supplicant/wpa_cli.c
index e700d7e..bd84a19 100644
--- a/wpa_supplicant/wpa_cli.c
+++ b/wpa_supplicant/wpa_cli.c
@@ -173,11 +173,9 @@ static void cli_txt_list_del_word(struct dl_list *txt_list, const char *txt)
end = os_strchr(txt, ' ');
if (end == NULL)
end = txt + os_strlen(txt);
- buf = os_malloc(end - txt + 1);
+ buf = dup_binstr(txt, end - txt);
if (buf == NULL)
return;
- os_memcpy(buf, txt, end - txt);
- buf[end - txt] = '\0';
cli_txt_list_del(txt_list, buf);
os_free(buf);
}
@@ -223,11 +221,9 @@ static int cli_txt_list_add_word(struct dl_list *txt_list, const char *txt)
end = os_strchr(txt, ' ');
if (end == NULL)
end = txt + os_strlen(txt);
- buf = os_malloc(end - txt + 1);
+ buf = dup_binstr(txt, end - txt);
if (buf == NULL)
return -1;
- os_memcpy(buf, txt, end - txt);
- buf[end - txt] = '\0';
ret = cli_txt_list_add(txt_list, buf);
os_free(buf);
return ret;