Merge pull request #163 from laijs/c-string

enable using api command data as c-string inplace
This commit is contained in:
Gao feng
2016-09-14 05:25:14 -04:00
committed by GitHub
2 changed files with 5 additions and 1 deletions
+3 -1
View File
@@ -166,7 +166,9 @@ int hyper_event_read(struct hyper_event *he, int efd)
}
fprintf(stdout, "get length %" PRIu32"\n", len);
if (len > buf->size) {
// test it with '>=' to leave at least one byte in handle(),
// so that handle() can convert the data to c-string inplace.
if (len >= buf->size) {
fprintf(stderr, "get length %" PRIu32", too long\n", len);
return -1;
}
+2
View File
@@ -1062,6 +1062,8 @@ static int hyper_channel_handle(struct hyper_event *de, uint32_t len)
uint8_t *data = NULL;
int i, ret = 0;
// append a null byte to it. hyper_event_read() left this room for us.
buf->data[buf->get] = 0;
for (i = 0; i < buf->get; i++)
fprintf(stdout, "%0x ", buf->data[i]);