From: Szymon Janc <szymon.janc@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Szymon Janc <szymon.janc@gmail.com>
Subject: [PATCH 6/7] shared/hfp: Don't update offset if string parsing failed
Date: Tue, 11 Mar 2014 00:10:33 +0100 [thread overview]
Message-ID: <1394493034-2417-6-git-send-email-szymon.janc@gmail.com> (raw)
In-Reply-To: <1394493034-2417-1-git-send-email-szymon.janc@gmail.com>
---
src/shared/hfp.c | 29 +++++++++++++++++++----------
1 file changed, 19 insertions(+), 10 deletions(-)
diff --git a/src/shared/hfp.c b/src/shared/hfp.c
index 3256931..36c8c3e 100644
--- a/src/shared/hfp.c
+++ b/src/shared/hfp.c
@@ -299,20 +299,22 @@ bool hfp_gw_result_get_string(struct hfp_gw_result *result, char *buf,
{
int i = 0;
const char *data = result->data;
+ unsigned int offset;
skip_whitespace(result);
if (data[result->offset] != '"')
return false;
- result->offset++;
+ offset = result->offset;
+ offset++;
- while (data[result->offset] != '\0' && data[result->offset] != '"') {
+ while (data[offset] != '\0' && data[offset] != '"') {
if (i == len)
return false;
- buf[i++] = data[result->offset];
- result->offset++;
+ buf[i++] = data[offset];
+ offset++;
}
if (i == len)
@@ -320,11 +322,13 @@ bool hfp_gw_result_get_string(struct hfp_gw_result *result, char *buf,
buf[i] = '\0';
- if (data[result->offset] == '"')
- result->offset++;
+ if (data[offset] == '"')
+ offset++;
else
return false;
+ result->offset = offset;
+
skip_whitespace(result);
next_field(result);
@@ -335,6 +339,7 @@ bool hfp_gw_result_get_unquoted_string(struct hfp_gw_result *result, char *buf,
uint8_t len)
{
const char *data = result->data;
+ unsigned int offset;
int i = 0;
char c;
@@ -344,13 +349,15 @@ bool hfp_gw_result_get_unquoted_string(struct hfp_gw_result *result, char *buf,
if (c == '"' || c == ')' || c == '(')
return false;
- while (data[result->offset] != '\0' && data[result->offset] != ','
- && data[result->offset] != ')') {
+ offset = result->offset;
+
+ while (data[offset] != '\0' && data[offset] != ',' &&
+ data[offset] != ')') {
if (i == len)
return false;
- buf[i++] = data[result->offset];
- result->offset++;
+ buf[i++] = data[offset];
+ offset++;
}
if (i == len)
@@ -358,6 +365,8 @@ bool hfp_gw_result_get_unquoted_string(struct hfp_gw_result *result, char *buf,
buf[i] = '\0';
+ result->offset = offset;
+
next_field(result);
return true;
--
1.9.0
next prev parent reply other threads:[~2014-03-10 23:10 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-10 23:10 [PATCH 1/7] unit/test-hfp: Add ability to pass custom result handler to test Szymon Janc
2014-03-10 23:10 ` [PATCH 2/7] unit/test-hfp: Add initial tests for getting unquoted string Szymon Janc
2014-03-10 23:10 ` [PATCH 3/7] unit/test-hfp: Add initial tests for getting quoted string Szymon Janc
2014-03-10 23:10 ` [PATCH 4/7] shared/hfp: Fix not NULL terminating parsed strings Szymon Janc
2014-03-10 23:10 ` [PATCH 5/7] shared/hfp: Use unsigned int for offset Szymon Janc
2014-03-10 23:10 ` Szymon Janc [this message]
2014-03-10 23:10 ` [PATCH 7/7] doc: Update test-hfp coverage statistics Szymon Janc
2014-03-11 20:10 ` [PATCH 1/7] unit/test-hfp: Add ability to pass custom result handler to test Szymon Janc
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1394493034-2417-6-git-send-email-szymon.janc@gmail.com \
--to=szymon.janc@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox