From a597c7f2c91509b70311d77c53abb7dcd5d27f22 Mon Sep 17 00:00:00 2001 From: moticless Date: Thu, 21 Sep 2023 13:14:02 +0300 Subject: [PATCH] Fixing signed int encoded --- src/lib/parser.c | 2 +- test/dumps/string_int_encoded.json | 57 +++++++++++++++++++++++++++++ test/dumps/string_int_encoded.rdb | Bin 0 -> 1427 bytes test/test_rdb_to_json.c | 7 ++++ 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 test/dumps/string_int_encoded.json create mode 100644 test/dumps/string_int_encoded.rdb diff --git a/src/lib/parser.c b/src/lib/parser.c index b2150c7..1e9adcf 100644 --- a/src/lib/parser.c +++ b/src/lib/parser.c @@ -1867,7 +1867,7 @@ RdbStatus rdbLoadInteger(RdbParser *p, int enctype, AllocTypeRq type, char *refB if (enctype == RDB_ENC_INT8) { IF_NOT_OK_RETURN(rdbLoad(p, 1, RQ_ALLOC, NULL, binfo)); - val = ((unsigned char *) (*binfo)->ref)[0]; + val = ((signed char *) (*binfo)->ref)[0]; } else if (enctype == RDB_ENC_INT16) { uint16_t v; IF_NOT_OK_RETURN(rdbLoad(p, 2, RQ_ALLOC, NULL, binfo)); diff --git a/test/dumps/string_int_encoded.json b/test/dumps/string_int_encoded.json new file mode 100644 index 0000000..89ecaa6 --- /dev/null +++ b/test/dumps/string_int_encoded.json @@ -0,0 +1,57 @@ +"str::-4294967295":"-4294967295", +"str::255":"255", +"str::-16777217":"-16777217", +"str::16777218":"16777218", +"str::-4294967297":"-4294967297", +"str::257":"257", +"str::2147483649":"2147483649", +"str::-16777215":"-16777215", +"str::3":"3", +"str::-281474976710656":"-281474976710656", +"str::-16777214":"-16777214", +"str::-65534":"-65534", +"str::256":"256", +"str::65535":"65535", +"str::-258":"-258", +"str::-256":"-256", +"str::254":"254", +"str::-4294967294":"-4294967294", +"str::16777217":"16777217", +"str::-281474976710655":"-281474976710655", +"str::16777216":"16777216", +"str::-255":"-255", +"str::-4294967298":"-4294967298", +"str::-1":"-1", +"str::281474976710655":"281474976710655", +"str::1":"1", +"str::0":"0", +"str::-281474976710654":"-281474976710654", +"str::-65538":"-65538", +"str::-254":"-254", +"str::-16777216":"-16777216", +"str::281474976710654":"281474976710654", +"str::281474976710657":"281474976710657", +"str::-281474976710657":"-281474976710657", +"str::258":"258", +"str::9223372036854780000":"9223372036854780000", +"str::16777214":"16777214", +"str::-257":"-257", +"str::2":"2", +"str::2147483650":"2147483650", +"str::16777215":"16777215", +"str::-65537":"-65537", +"str::65537":"65537", +"str::-65536":"-65536", +"str::-16777218":"-16777218", +"str::65534":"65534", +"str::-4294967296":"-4294967296", +"str::65538":"65538", +"str::2147483646":"2147483646", +"str::281474976710658":"281474976710658", +"str::2147483648":"2147483648", +"str::281474976710656":"281474976710656", +"str::-9223372036854780000":"-9223372036854780000", +"str::-65535":"-65535", +"str::65536":"65536", +"str::2147483647":"2147483647", +"str::-281474976710658":"-281474976710658" diff --git a/test/dumps/string_int_encoded.rdb b/test/dumps/string_int_encoded.rdb new file mode 100644 index 0000000000000000000000000000000000000000..a2e2d01d4365685f6353fb1e137acc247139acbb GIT binary patch literal 1427 zcmZux!A{&T5FKw-SawSn36R=TKcGsLIJU>(!~qVywqF1xmG-czv{`!P*W!Fg52)h8 zg>#T%>?BGYuOmfr#-5q?p5Nrh_0{*EahxRe(Kf$Z7t!B*yQG|d>)(3Og>TopqP(o% z|JtoLdG+t~LtfACi~KIyZAOLylUQ(Z5_tiy46_h5EW2dEd1@nC53qzX3>NLS-Q|WR037wr zxKvFuewo8#CR5G6p3LFSrfQ*OM8Z6{&x22MMP)#d5eQdA@98d`-VzQw3Q4KqtX)op z;w$gFmpUm)zluu;gJnKg=ISe}MmKtd%G6AIm(sEc!(tvR76gypDGUQeAL!^tsb&N| zwYp@KrYX`m6_PWQv3X7dvFU{{!_pXK@Chn29GzKdIrDtZ}{2E&+VAsW~C6E7T>2<`0;GV-@7?GtMMV-I1!NZ&6~|9?DwJbZro`UXtKe8m6& literal 0 HcmV?d00001 diff --git a/test/test_rdb_to_json.c b/test/test_rdb_to_json.c index 2dc4e65..d9ad3e6 100644 --- a/test/test_rdb_to_json.c +++ b/test/test_rdb_to_json.c @@ -397,6 +397,12 @@ static void test_r2j_module_aux_data(void **state) { testRdbToJsonCommon(DUMP_FOLDER("module_aux.rdb"), DUMP_FOLDER("module_aux_data.json"), &r2jConf); } +static void test_r2j_string_int_encoded(void **state) { + UNUSED(state); + RdbxToJsonConf r2jConf = DEF_CONF(RDB_LEVEL_DATA); + r2jConf.includeAuxField = 0; + testRdbToJsonCommon(DUMP_FOLDER("string_int_encoded.rdb"), DUMP_FOLDER("string_int_encoded.json"), &r2jConf); +} /*************************** group_rdb_to_json *******************************/ int group_rdb_to_json(void) { const struct CMUnitTest tests[] = { @@ -462,6 +468,7 @@ int group_rdb_to_json(void) { cmocka_unit_test(test_r2j_multiple_lists_and_strings_struct), cmocka_unit_test(test_r2j_multiple_lists_and_strings_raw), cmocka_unit_test(test_r2j_multiple_dbs), + cmocka_unit_test(test_r2j_string_int_encoded), }; return cmocka_run_group_tests(tests, NULL, NULL); }