From a59fbdfe7fefcca1baefdbfda379d5dc9383210b Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Tue, 14 Jul 2015 11:32:11 +0100 Subject: Add a test for pickling and unpickling sessions, fix off by one error when unpickling sessions --- src/olm.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/olm.cpp b/src/olm.cpp index 6f6d8ba..53cae54 100644 --- a/src/olm.cpp +++ b/src/olm.cpp @@ -152,7 +152,7 @@ std::size_t b64_input( return raw_length; } -const char * errors[11] { +static const char * ERRORS[11] { "SUCCESS", "NOT_ENOUGH_RANDOM", "OUTPUT_BUFFER_TOO_SMALL", @@ -181,8 +181,8 @@ const char * olm_account_last_error( OlmSession * account ) { unsigned error = unsigned(from_c(account)->last_error); - if (error < 9) { - return errors[error]; + if (error < sizeof(ERRORS)) { + return ERRORS[error]; } else { return "UNKNOWN_ERROR"; } @@ -193,8 +193,8 @@ const char * olm_session_last_error( OlmSession * session ) { unsigned error = unsigned(from_c(session)->last_error); - if (error < 9) { - return errors[error]; + if (error < sizeof(ERRORS)) { + return ERRORS[error]; } else { return "UNKNOWN_ERROR"; } @@ -337,7 +337,7 @@ size_t olm_unpickle_session( return std::size_t(-1); } - std::uint8_t * const end = pos + raw_length + 1; + std::uint8_t * const end = pos + raw_length; /* On success unpickle will return (pos + raw_length). If unpickling * terminates too soon then it will return a pointer before * (pos + raw_length). On error unpickle will return (pos + raw_length + 1). -- cgit v1.2.3