aboutsummaryrefslogtreecommitdiff
path: root/rmihidtool
diff options
context:
space:
mode:
authorAndrew Duggan <aduggan@synaptics.com>2014-11-13 21:15:48 -0800
committerAndrew Duggan <aduggan@synaptics.com>2014-11-14 12:23:22 -0800
commit849fea35a5aa27e84f041ea74d427945018c97e6 (patch)
treef91201b79900f6f33cd0e11a96e0b0bc52df7bc4 /rmihidtool
parentd2e1d579bda5c1d89bd9d23a940982ac92d8dc2e (diff)
downloadrmi4utils-849fea35a5aa27e84f041ea74d427945018c97e6.tar.gz
Fix string parsing bugs which prevented write commands from working correctly
Diffstat (limited to 'rmihidtool')
-rw-r--r--rmihidtool/main.cpp15
1 files changed, 6 insertions, 9 deletions
diff --git a/rmihidtool/main.cpp b/rmihidtool/main.cpp
index 8fcb858..1202d07 100644
--- a/rmihidtool/main.cpp
+++ b/rmihidtool/main.cpp
@@ -85,10 +85,8 @@ int find_token(char * input, char * result, char ** endpp)
}
while (input[i] != '\0') {
- ++i;
- if (input[i] == ' ') {
+ if (input[++i] == ' ')
break;
- }
}
end = &input[i];
@@ -97,13 +95,11 @@ int find_token(char * input, char * result, char ** endpp)
*endpp = end;
strncpy(result, start, end - start);
- result[end - start + 1] = '\0';
+ result[end - start] = '\0';
return 1;
}
-
-
void interactive(RMIDevice * device, unsigned char *report)
{
char token[256];
@@ -157,8 +153,7 @@ void interactive(RMIDevice * device, unsigned char *report)
memset(report, 0, 256);
while (find_token(start, token, &end)) {
start = end;
- report[index] = strtol(token, NULL, 0);
- ++index;
+ report[index++] = strtol(token, NULL, 0);
++len;
}
@@ -220,6 +215,7 @@ int main(int argc, char ** argv)
char * data = NULL;
char * start;
char * end;
+ int i = 0;
memset(&sig_cleanup_action, 0, sizeof(struct sigaction));
sig_cleanup_action.sa_handler = cleanup;
@@ -298,11 +294,12 @@ int main(int argc, char ** argv)
print_buffer(report, len);
break;
case RMIHIDTOOL_CMD_WRITE:
+ i = 0;
start = data;
memset(report, 0, sizeof(report));
while (find_token(start, token, &end)) {
start = end;
- report[index++] = (unsigned char)strtol(token, NULL, 0);
+ report[i++] = (unsigned char)strtol(token, NULL, 0);
++len;
}