From 021ab9764a9c0c1487cab384860730d8bc73a476 Mon Sep 17 00:00:00 2001 From: Toon Stegen <tstegen@nalys-group.com> Date: Tue, 18 Sep 2018 10:57:24 +0200 Subject: [PATCH] at driver: fix at_send_cmd_get_lines bug When reusing the same buffer for the at command and response, no command would be sent because the buffer was cleared. This is fixed by only clearing the buffer after the command has been sent. --- drivers/at/at.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/at/at.c b/drivers/at/at.c index 175200deef..84ad661afc 100644 --- a/drivers/at/at.c +++ b/drivers/at/at.c @@ -121,8 +121,6 @@ ssize_t at_send_cmd_get_lines(at_dev_t *dev, const char *command, size_t bytes_left = len - 1; char *pos = resp_buf; - memset(resp_buf, '\0', len); - at_drain(dev); res = at_send_cmd(dev, command, timeout); @@ -130,6 +128,10 @@ ssize_t at_send_cmd_get_lines(at_dev_t *dev, const char *command, goto out; } + /* only clear the response buffer after sending the command, + * so the same buffer can be used for command and response */ + memset(resp_buf, '\0', len); + while (1) { res = at_readline(dev, pos, bytes_left, keep_eol, timeout); if (res == 0) { -- GitLab