Skip to content
Snippets Groups Projects
Commit 3d604f0a authored by mechanik20051988's avatar mechanik20051988 Committed by Vladimir Davydov
Browse files

msgpack: fixed incorrect print of msgpack field

Due to the fact that we used `const char**` to save a pointer to the
original msgpack header, when restoring the pointer, we received an
incorrect value and as a consequence assertion failure later. Correctly
saving and restoring the pointer fixed this problem.

NO_DOC=bug fix
NO_CHANGELOG=bug fix
parent 438ce64e
No related branches found
No related tags found
No related merge requests found
......@@ -40,7 +40,7 @@
static int
msgpack_fprint_ext(FILE *file, const char **data, int depth)
{
const char **orig = data;
const char *orig = *data;
int8_t type;
uint32_t len = mp_decode_extl(data, &type);
switch(type) {
......@@ -53,14 +53,15 @@ msgpack_fprint_ext(FILE *file, const char **data, int depth)
case MP_ERROR:
return mp_fprint_error(file, data, depth);
default:
return mp_fprint_ext_default(file, orig, depth);
*data = orig;
return mp_fprint_ext_default(file, data, depth);
}
}
static int
msgpack_snprint_ext(char *buf, int size, const char **data, int depth)
{
const char **orig = data;
const char *orig = *data;
int8_t type;
uint32_t len = mp_decode_extl(data, &type);
switch(type) {
......@@ -73,7 +74,8 @@ msgpack_snprint_ext(char *buf, int size, const char **data, int depth)
case MP_ERROR:
return mp_snprint_error(buf, size, data, depth);
default:
return mp_snprint_ext_default(buf, size, orig, depth);
*data = orig;
return mp_snprint_ext_default(buf, size, data, depth);
}
}
......
......@@ -140,6 +140,9 @@ if (ENABLE_BUNDLED_MSGPUCK)
target_link_libraries(msgpack.test ${MSGPUCK_LIBRARIES})
endif ()
add_executable(mp_print_unknown_ext.test mp_print_unknown_ext.c)
target_link_libraries(mp_print_unknown_ext.test unit box core)
add_executable(scramble.test scramble.c core_test_utils.c)
target_link_libraries(scramble.test scramble)
......
#include "msgpack.h"
#include "mp_extension_types.h"
#include "trivia/util.h"
#include "unit.h"
#include <stdio.h>
static int
test_mp_print(const char *sample, const char *ext_data)
{
plan(2);
char str[200] = {0};
mp_snprint(str, sizeof(str), ext_data);
is(strcmp(sample, str), 0, "mp_snprint unknown extension");
memset(str, 0, sizeof(str));
FILE *f = tmpfile();
assert(f != NULL);
mp_fprint(f, ext_data);
rewind(f);
fread(str, 1, sizeof(str), f);
is(strcmp(sample, str), 0, "mp_fprint unknown extension");
return check_plan();
}
static int
test_mp_print_unknown_extention(void)
{
plan(1);
char sample[] = "(extension: type 0, len 10)";
char data[] = { 0xca, 0xca, 0xca, 0xca, 0xca, 0xca, 0xca, 0xca, 0xca, 0xca };
char *ext_data = xmalloc(mp_sizeof_ext(sizeof(data)));
char *data_end = ext_data;
data_end = mp_encode_ext(data_end, MP_UNKNOWN_EXTENSION, data, sizeof(data));
test_mp_print(sample, ext_data);
free(ext_data);
return check_plan();
}
int
main(void)
{
plan(1);
msgpack_init();
test_mp_print_unknown_extention();
return check_plan();
}
1..1
1..1
1..2
ok 1 - mp_snprint unknown extension
ok 2 - mp_fprint unknown extension
ok 1 - subtests
ok 1 - subtests
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment