protocol

protocol tests
Log | Files | Refs | Submodules | README | git clone https://git.ne02ptzero.me/git/protocol

commit b4ec436ef94fe34bfb2510da4beee4c74eeac81d
parent 098e4db013b7df916bf3a077a191775f544f3bcd
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Mon, 20 Mar 2017 16:52:25 +0100

Fix(write_package): Wrong size of ... size. (32 -> 16)

Diffstat:
Msrc/client_test.c | 3++-
Msrc/package.c | 3++-
Msrc/write_package.c | 3++-
3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/client_test.c b/src/client_test.c @@ -45,7 +45,8 @@ TEST(pkg_auth_1_read) { READ_TIMEOUT(sockfd, ret, 2048, 1, r_n); TEST_ASSERT_FMT(r_n == size, "Package returned size is wrong (%zu - %zu) %s", r_n, size, print_package(expect, ret, size, r_n)); - TEST_ASSERT(memcmp(ret, expect, size) == 0, "Expected package is wrong"); + TEST_ASSERT_FMT(memcmp(ret, expect, size) == 0, + "Expected package is wrong %s", print_package(expect, ret, size, r_n)); pkg = read_pkg(ret); TEST_ASSERT(pkg, "Can't read package"); TEST_ASSERT(pkg->type == PKG_TYPE_AUTH_ACK, "Package type is wrong"); diff --git a/src/package.c b/src/package.c @@ -247,8 +247,9 @@ char *print_package(void *exp, void *ret, size_t exp_size, size_t ret_size) { asprintf(&res, "%s\033[0;31m%02x\033[0;37m ", res, s_ret[i]); else asprintf(&res, "%s%02x ", res, s_ret[i]); - if (i % 10) + if (i % 10 == 0 && i != 0) asprintf(&res, "%s\n ",res); } + asprintf(&res, "%s\n ",res); return res; } diff --git a/src/write_package.c b/src/write_package.c @@ -301,7 +301,8 @@ void *write_package(package_t *pkg, size_t *size) { *size = header_size + payload_size; ret = malloc(*size); - memcpy(header + 1, size, sizeof(*size)); + u16_t size_tmp = (u16_t)*size; + memcpy(header + 1, &size_tmp, sizeof(size_tmp)); assert(ret != NULL); memcpy(ret, header, header_size); memcpy(ret + header_size, payload, payload_size);