Diff between 47ea0048e2b00a413b56fdb76370b9ac4bd4ae9c and 104a987024658098c05c9f6dedecfd42d7e06aef

Changed Files

File Additions Deletions Status
src/shared/hfp.c +19 -10 modified

Full Patch

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;