GithubHelp home page GithubHelp logo

rtsisyk / msgpuck Goto Github PK

View Code? Open in Web Editor NEW
85.0 85.0 28.0 300 KB

A simple and efficient MsgPack binary serialization library in a self-contained header file

License: BSD 2-Clause "Simplified" License

C 95.96% CMake 2.78% Makefile 1.25%

msgpuck's People

Contributors

alexandermyasnikov avatar alyapunov avatar amdrozdov avatar bigbes avatar gahr avatar georgykirichenko avatar locker avatar rtsisyk avatar unera avatar xiongyihui avatar zloidemon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

msgpuck's Issues

SIGBUS on mp_float_bswap on armv6l

ok 3 - subtests
    1..27
    # *** test_floats ***
    # float (float) 1.0
    ok 1 - mp_check_float((float) 1.0) == 0

Program received signal SIGBUS, Bus error.
(gdb) bt
#0  0x0003c974 in mp_decode_float (data=0xbefff5bc) at /home/roman/work/tarantool/master/src/lib/msgpuck/msgpuck.h:1386
#1  0x0001b568 in test_floats () at /home/roman/work/tarantool/master/src/lib/msgpuck/test/msgpuck.c:163
#2  0x0003ac8c in main () at /home/roman/work/tarantool/master/src/lib/msgpuck/test/msgpuck.c:488

FTBFS with -Werror=sign-compare

[ 84%] Building C object test/unit/CMakeFiles/msgpack.test.dir/__/__/src/lib/msgpuck/test/msgpuck.c.o
In file included from /home/mons/src/tarantool/src/lib/msgpuck/test/msgpuck.c:39:0:
/home/mons/src/tarantool/src/lib/msgpuck/test/msgpuck.c: In function ‘test_format’:
/home/mons/src/tarantool/src/lib/msgpuck/test/msgpuck.c:702:12: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
  ok((c - p == data1_len) &&
            ^
/home/mons/src/tarantool/src/lib/msgpuck/test/test.h:83:17: note: in definition of macro ‘ok’
  int res = __ok(condition, fmt, ##args);  \
                 ^
/home/mons/src/tarantool/src/lib/msgpuck/test/msgpuck.c: At top level:
cc1: error: unrecognized command line option "-Wno-tautological-compare" [-Werror]
cc1: error: unrecognized command line option "-Wno-format-truncation" [-Werror]
cc1: all warnings being treated as errors
test/unit/CMakeFiles/msgpack.test.dir/build.make:62: recipe for target 'test/unit/CMakeFiles/msgpack.test.dir/__/__/src/lib/msgpuck/test/msgpuck.c.o' failed
make[2]: *** [test/unit/CMakeFiles/msgpack.test.dir/__/__/src/lib/msgpuck/test/msgpuck.c.o] Error 1
CMakeFiles/Makefile2:3133: recipe for target 'test/unit/CMakeFiles/msgpack.test.dir/all' failed
make[1]: *** [test/unit/CMakeFiles/msgpack.test.dir/all] Error 2
Makefile:149: recipe for target 'all' failed
make: *** [all] Error 2

gcc version 4.9.3 (Funtoo 4.9.3-r1)

assertion failed when use mp_encode_int

hello, all
I have been using this libray, but failed at encode_int. when I looked into the code, I found:
"
MP_IMPL char *
mp_encode_int(char *data, int64_t num)
{
assert(num < 0);
if (num >= -0x20) {

"
what's the reason to force "num <0"

Add helpers to decode any number to int64/double

Proposal 1:

/*
 * Decodes an integer or a floting point value as double.
 *
 * \param data the pointer to a buffer
 * \param deflt a value to return on error
 * \retval number on success
 * \retval deflt on overflow
 * \retval deflt if underlying mp type is not MP_INT, MP_UINT,
 *         MP_FLOAT or MP_DOUBLE.
 */
static inline double
mp_read_double(const char **data, double deflt);

/*
 * Decodes an integer value as int64_t.
 *
 * \param data the pointer to a buffer
 * \param deflt a value to return on error
 * \retval number on success
 * \retval deflt on overflow
 * \retval deflt if underlying mp type is not MP_INT, MP_UINT.
 */
static inline double
mp_read_int64(const char **data, int64_t deflt);

Proposal 2:

/*
 * Decodes an integer or a floting point value as double.
 *
 * \param[out] ret return value
 * \retval  0 on success
 * \retval -1 on overflow, *ret is set to zero
 * \retval -1 if underlying mp type is not MP_INT, MP_UINT,
 *         MP_FLOAT or MP_DOUBLE, *ret is set to zero.
 */
static inline int
mp_read_double(const char **data, double *ret);

/*
 * Decodes an integer value as int64_t.
 *
 * \param[out] ret return value
 * \retval  0 on success
 * \retval -1 on overflow, *ret is set to zero
 * \retval -1 if underlying mp type is not MP_INT, MP_UINT, *ret is set to zero
 */
static inline int
mp_read_int64(const char **data, int64_t *ret);

mp_decode_double() is already used, mp_decode_int64() is reserved for the future.
Any other ideas?

  1. mp_read_int64
  2. mp_convert_int64
  3. mp_to_int64
  4. mp_decode_int/mp_decode_double and rename current mp_decode_int()/mp_decode_double() to mp_decode_i64()/mp_decode_f64()

typeof mutation

Hello,

First, thanks for this great "inline" msgpuck.
I was facing a typeof mutation problem which seems normal in the code but a bit disturbing when i worked on it.
You can not just do a mp_encode_int / mp_decode_int.
In this case, you must call the mp_typeof before the decode because the int could be changed to a uint if (0<=i<=127).

mp_encode_int( s, 1 ); assert(mp_typeof(*s) == MP_INT);

Perhaps it should be specified in the documentation.
Regards,

Test “mp_read_double(mp_encode_double(-5.555)) check result” fails on x86

msgpuck 2.0 with backported 40e24cc.

Test mp_read_double(mp_encode_double(-5.555)) check result fails on x86, but not x86_64.

    ok 61 - mp_read_double(mp_encode_uint(123)) check success
    ok 62 - mp_read_double(mp_encode_uint(123)) check pos advanced
    ok 63 - mp_read_double(mp_encode_uint(123)) check result
    ok 64 - mp_read_double(mp_encode_uint(12345)) check success
    ok 65 - mp_read_double(mp_encode_uint(12345)) check pos advanced
    ok 66 - mp_read_double(mp_encode_uint(12345)) check result
    ok 67 - mp_read_double(mp_encode_uint(123456789)) check success
    ok 68 - mp_read_double(mp_encode_uint(123456789)) check pos advanced
    ok 69 - mp_read_double(mp_encode_uint(123456789)) check result
    ok 70 - mp_read_double(mp_encode_uint(1234567890000ULL)) check success
    ok 71 - mp_read_double(mp_encode_uint(1234567890000ULL)) check pos advanced
    ok 72 - mp_read_double(mp_encode_uint(1234567890000ULL)) check result
    ok 73 - mp_read_double(mp_encode_uint(123456789123456789ULL)) check fail
    ok 74 - mp_read_double(mp_encode_uint(123456789123456789ULL)) check pos unchanged
    ok 75 - mp_read_double(mp_encode_int(-123)) check success
    ok 76 - mp_read_double(mp_encode_int(-123)) check pos advanced
    ok 77 - mp_read_double(mp_encode_int(-123)) check result
    ok 78 - mp_read_double(mp_encode_int(-12345)) check success
    ok 79 - mp_read_double(mp_encode_int(-12345)) check pos advanced
    ok 80 - mp_read_double(mp_encode_int(-12345))    #   Failed test 'mp_read_double(mp_encode_double(-5.555)) check result'
    #   in /home/buildozer/aports/testing/msgpuck/src/msgpuck-2.0/test/msgpuck.c at line 1051
 check result
    ok 81 - mp_read_double(mp_encode_int(-123456789)) check success
    ok 82 - mp_read_double(mp_encode_int(-123456789)) check pos advanced
    ok 83 - mp_read_double(mp_encode_int(-123456789)) check result
    ok 84 - mp_read_double(mp_encode_int(-1234567890000LL)) check success
    ok 85 - mp_read_double(mp_encode_int(-1234567890000LL)) check pos advanced
    ok 86 - mp_read_double(mp_encode_int(-1234567890000LL)) check result
    ok 87 - mp_read_double(mp_encode_int(-123456789123456789LL)) check fail
    ok 88 - mp_read_double(mp_encode_int(-123456789123456789LL)) check pos unchanged
    ok 89 - mp_read_double(mp_encode_float(6.565e6)) check success
    ok 90 - mp_read_double(mp_encode_float(6.565e6)) check pos advanced
    ok 91 - mp_read_double(mp_encode_float(6.565e6)) check result
    ok 92 - mp_read_double(mp_encode_double(-5.555)) check success
    ok 93 - mp_read_double(mp_encode_double(-5.555)) check pos advanced
-> not ok 94 - mp_read_double(mp_encode_double(-5.555)) check result <-
        # Looks like you failed 1 test of 96 run.
#   Failed test 'subtests'
#   in /home/buildozer/aports/testing/msgpuck/src/msgpuck-2.0/test/test.c at line 85
# Looks like you failed 1 test of 20 run.
ok 95 - mp_read_double(mp_encode_strl(100)) check fail
    ok 96 - mp_read_double(mp_encode_strl(100)) check pos unchanged
    # *** test_numbers: done ***
not ok 19 - subtests

Cannot build under aarch64-linux-gnu-gcc

cmake -S Common/Import/msgpuck -B Common/Import/msgpuck/build
1141-- The CXX compiler identification is GNU 10.2.1
1142-- Detecting C compiler ABI info
1143-- The C compiler identification is GNU 10.2.1
1144-- Detecting C compiler ABI info
1145-- Detecting C compiler ABI info - done
1146-- Detecting C compiler ABI info - done
1147-- Check for working C compiler: /usr/bin/aarch64-linux-gnu-gcc - skipped
1148-- Detecting C compile features
1149-- Detecting C compile features - done
1150-- Detecting CXX compiler ABI info
1151-- Check for working C compiler: /usr/bin/aarch64-linux-gnu-gcc - skipped
1152-- Detecting C compile features
1153-- Detecting C compile features - done
1154-- Performing Test CC_HAS_MNO_UNALIGNED_ACCESS
1155-- Performing Test CC_HAS_MNO_UNALIGNED_ACCESS - Failed

PVS-Studio problems

The list of problems found by PVS Studio by Viva64 in 1.1-6-g466b6a6:

  • test/msgpuck.c:350 warn V512 A call of the 'memcmp' function will lead to underflow of the buffer 's1'.
  • test/msgpuck.c:351 warn V512 A call of the 'memcmp' function will lead to underflow of the buffer 's1'.
  • test/msgpuck.c:352 warn V512 A call of the 'memcmp' function will lead to underflow of the buffer 's1'.
  • test/msgpuck.c:353 warn V512 A call of the 'memcmp' function will lead to underflow of the buffer 's1'.
  • test/msgpuck.c:354 warn V512 A call of the 'memcmp' function will lead to underflow of the buffer 's1'.
  • test/msgpuck.c:355 warn V512 A call of the 'memcmp' function will lead to underflow of the buffer 's1'.
  • test/msgpuck.c:356 warn V512 A call of the 'memcmp' function will lead to underflow of the buffer 's1'.
  • test/msgpuck.c:357 warn V512 A call of the 'memcmp' function will lead to underflow of the buffer 's1'.
  • test/msgpuck.c:358 warn V512 A call of the 'memcmp' function will lead to underflow of the buffer 's1'.
  • test/msgpuck.c:359 warn V512 A call of the 'memcmp' function will lead to underflow of the buffer 's1'.
  • test/msgpuck.c:360 warn V512 A call of the 'memcmp' function will lead to underflow of the buffer 's1'.
  • test/msgpuck.c:361 warn V512 A call of the 'memcmp' function will lead to underflow of the buffer 's1'.
  • test/msgpuck.c:373 warn V512 A call of the 'memcmp' function will lead to underflow of the buffer 's1'.
  • test/msgpuck.c:374 warn V512 A call of the 'memcmp' function will lead to underflow of the buffer 's1'.
  • test/msgpuck.c:375 warn V512 A call of the 'memcmp' function will lead to underflow of the buffer 's1'.
  • test/msgpuck.c:376 warn V512 A call of the 'memcmp' function will lead to underflow of the buffer 's1'.
  • test/msgpuck.c:377 warn V512 A call of the 'memcmp' function will lead to underflow of the buffer 's1'.
  • test/msgpuck.c:378 warn V512 A call of the 'memcmp' function will lead to underflow of the buffer 's1'.
  • test/msgpuck.c:379 warn V512 A call of the 'memcmp' function will lead to underflow of the buffer 's1'.
  • test/msgpuck.c:380 warn V512 A call of the 'memcmp' function will lead to underflow of the buffer 's1'.
  • test/msgpuck.c:381 warn V512 A call of the 'memcmp' function will lead to underflow of the buffer 's1'.
  • test/msgpuck.c:382 warn V512 A call of the 'memcmp' function will lead to underflow of the buffer 's1'.
  • test/msgpuck.c:383 warn V512 A call of the 'memcmp' function will lead to underflow of the buffer 's1'.
  • test/msgpuck.c:384 warn V512 A call of the 'memcmp' function will lead to underflow of the buffer 's1'.
  • test/msgpuck.c:706 warn V587 An odd sequence of assignments of this kind: A = B; B = A;. Check lines: 704, 706.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.