From 4a70d70fa63a3ed8ef62651a09a4372736786c16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Mon, 10 Nov 2025 22:26:57 +0100 Subject: [PATCH 1/2] blobmsg: remove int16 support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit u16 has the same effective size as u32 so we can remove it to avoid a lot of compatibility mess and JSON conversion issues. Link: https://github.com/openwrt/libubox/pull/25 Signed-off-by: Álvaro Fernández Rojas --- blob.c | 1 - blob.h | 28 +++++--------------- blobmsg.c | 2 -- blobmsg.h | 22 ++++------------ blobmsg_json.c | 3 --- tests/cram/test_blobmsg.t | 18 ------------- tests/cram/test_blobmsg_types.t | 14 +--------- tests/fuzz/test-fuzz.c | 3 --- tests/test-blobmsg-types.c | 46 --------------------------------- tests/test-blobmsg.c | 7 ----- 10 files changed, 12 insertions(+), 132 deletions(-) diff --git a/blob.c b/blob.c index abcc9f2..179e35a 100644 --- a/blob.c +++ b/blob.c @@ -192,7 +192,6 @@ blob_nest_end(struct blob_buf *buf, void *cookie) static const size_t blob_type_minlen[BLOB_ATTR_LAST] = { [BLOB_ATTR_STRING] = 1, [BLOB_ATTR_INT8] = sizeof(uint8_t), - [BLOB_ATTR_INT16] = sizeof(uint16_t), [BLOB_ATTR_INT32] = sizeof(uint32_t), [BLOB_ATTR_INT64] = sizeof(uint64_t), [BLOB_ATTR_DOUBLE] = sizeof(double), diff --git a/blob.h b/blob.h index 13bc7cc..0f71344 100644 --- a/blob.h +++ b/blob.h @@ -36,7 +36,7 @@ enum { BLOB_ATTR_BINARY, BLOB_ATTR_STRING, BLOB_ATTR_INT8, - BLOB_ATTR_INT16, + __BLOB_ATTR_DEPRECATED_INT16, BLOB_ATTR_INT32, BLOB_ATTR_INT64, BLOB_ATTR_DOUBLE, @@ -128,13 +128,6 @@ blob_get_u8(const struct blob_attr *attr) return *((uint8_t *) attr->data); } -static inline uint16_t -blob_get_u16(const struct blob_attr *attr) -{ - uint16_t *tmp = (uint16_t*)attr->data; - return be16_to_cpu(*tmp); -} - static inline uint32_t blob_get_u32(const struct blob_attr *attr) { @@ -151,18 +144,14 @@ blob_get_u64(const struct blob_attr *attr) return tmp; } +#define blob_get_u16 blob_get_u32 + static inline int8_t blob_get_int8(const struct blob_attr *attr) { return blob_get_u8(attr); } -static inline int16_t -blob_get_int16(const struct blob_attr *attr) -{ - return blob_get_u16(attr); -} - static inline int32_t blob_get_int32(const struct blob_attr *attr) { @@ -181,6 +170,8 @@ blob_get_string(const struct blob_attr *attr) return attr->data; } +#define blob_get_int16 blob_get_int32 + static inline struct blob_attr * blob_next(const struct blob_attr *attr) { @@ -215,13 +206,6 @@ blob_put_u8(struct blob_buf *buf, int id, uint8_t val) return blob_put(buf, id, &val, sizeof(val)); } -static inline struct blob_attr * -blob_put_u16(struct blob_buf *buf, int id, uint16_t val) -{ - val = cpu_to_be16(val); - return blob_put(buf, id, &val, sizeof(val)); -} - static inline struct blob_attr * blob_put_u32(struct blob_buf *buf, int id, uint32_t val) { @@ -237,7 +221,7 @@ blob_put_u64(struct blob_buf *buf, int id, uint64_t val) } #define blob_put_int8 blob_put_u8 -#define blob_put_int16 blob_put_u16 +#define blob_put_int16 blob_put_u32 #define blob_put_int32 blob_put_u32 #define blob_put_int64 blob_put_u64 diff --git a/blobmsg.c b/blobmsg.c index d87d607..d49b80d 100644 --- a/blobmsg.c +++ b/blobmsg.c @@ -17,7 +17,6 @@ static const int blob_type[__BLOBMSG_TYPE_LAST] = { [BLOBMSG_TYPE_INT8] = BLOB_ATTR_INT8, - [BLOBMSG_TYPE_INT16] = BLOB_ATTR_INT16, [BLOBMSG_TYPE_INT32] = BLOB_ATTR_INT32, [BLOBMSG_TYPE_INT64] = BLOB_ATTR_INT64, [BLOBMSG_TYPE_DOUBLE] = BLOB_ATTR_DOUBLE, @@ -202,7 +201,6 @@ int blobmsg_parse(const struct blobmsg_policy *policy, int policy_len, if (policy[i].type == BLOBMSG_CAST_INT64 && (blob_id(attr) != BLOBMSG_TYPE_INT64 && blob_id(attr) != BLOBMSG_TYPE_INT32 && - blob_id(attr) != BLOBMSG_TYPE_INT16 && blob_id(attr) != BLOBMSG_TYPE_INT8)) continue; diff --git a/blobmsg.h b/blobmsg.h index f2fc0d0..7b7469b 100644 --- a/blobmsg.h +++ b/blobmsg.h @@ -29,7 +29,7 @@ enum blobmsg_type { BLOBMSG_TYPE_STRING, BLOBMSG_TYPE_INT64, BLOBMSG_TYPE_INT32, - BLOBMSG_TYPE_INT16, + __BLOBMSG_TYPE_DEPRECATED_INT16, BLOBMSG_TYPE_INT8, BLOBMSG_TYPE_BOOL = BLOBMSG_TYPE_INT8, BLOBMSG_TYPE_DOUBLE, @@ -210,13 +210,6 @@ blobmsg_add_u8(struct blob_buf *buf, const char *name, uint8_t val) return blobmsg_add_field(buf, BLOBMSG_TYPE_INT8, name, &val, 1); } -static inline int -blobmsg_add_u16(struct blob_buf *buf, const char *name, uint16_t val) -{ - val = cpu_to_be16(val); - return blobmsg_add_field(buf, BLOBMSG_TYPE_INT16, name, &val, 2); -} - static inline int blobmsg_add_u32(struct blob_buf *buf, const char *name, uint32_t val) { @@ -244,6 +237,8 @@ blobmsg_add_blob(struct blob_buf *buf, struct blob_attr *attr) blobmsg_data(attr), blobmsg_data_len(attr)); } +#define blobmsg_add_u16 blobmsg_add_u32 + void *blobmsg_open_nested(struct blob_buf *buf, const char *name, bool array); static inline void * @@ -285,11 +280,6 @@ static inline bool blobmsg_get_bool(struct blob_attr *attr) return *(uint8_t *) blobmsg_data(attr); } -static inline uint16_t blobmsg_get_u16(struct blob_attr *attr) -{ - return be16_to_cpu(*(uint16_t *) blobmsg_data(attr)); -} - static inline uint32_t blobmsg_get_u32(struct blob_attr *attr) { return be32_to_cpu(*(uint32_t *) blobmsg_data(attr)); @@ -303,6 +293,8 @@ static inline uint64_t blobmsg_get_u64(struct blob_attr *attr) return tmp; } +#define blobmsg_get_u16 blobmsg_get_u32 + static inline uint64_t blobmsg_cast_u64(struct blob_attr *attr) { uint64_t tmp = 0; @@ -311,8 +303,6 @@ static inline uint64_t blobmsg_cast_u64(struct blob_attr *attr) tmp = blobmsg_get_u64(attr); else if (blobmsg_type(attr) == BLOBMSG_TYPE_INT32) tmp = blobmsg_get_u32(attr); - else if (blobmsg_type(attr) == BLOBMSG_TYPE_INT16) - tmp = blobmsg_get_u16(attr); else if (blobmsg_type(attr) == BLOBMSG_TYPE_INT8) tmp = blobmsg_get_u8(attr); @@ -327,8 +317,6 @@ static inline int64_t blobmsg_cast_s64(struct blob_attr *attr) tmp = blobmsg_get_u64(attr); else if (blobmsg_type(attr) == BLOBMSG_TYPE_INT32) tmp = (int32_t)blobmsg_get_u32(attr); - else if (blobmsg_type(attr) == BLOBMSG_TYPE_INT16) - tmp = (int16_t)blobmsg_get_u16(attr); else if (blobmsg_type(attr) == BLOBMSG_TYPE_INT8) tmp = (int8_t)blobmsg_get_u8(attr); diff --git a/blobmsg_json.c b/blobmsg_json.c index 31eec09..9f11d59 100644 --- a/blobmsg_json.c +++ b/blobmsg_json.c @@ -250,9 +250,6 @@ static void blobmsg_format_element(struct strbuf *s, struct blob_attr *attr, boo case BLOBMSG_TYPE_BOOL: snprintf(buf, sizeof(buf), "%s", *(uint8_t *)data ? "true" : "false"); break; - case BLOBMSG_TYPE_INT16: - snprintf(buf, sizeof(buf), "%" PRId16, (int16_t) be16_to_cpu(*(uint16_t *)data)); - break; case BLOBMSG_TYPE_INT32: snprintf(buf, sizeof(buf), "%" PRId32, (int32_t) be32_to_cpu(*(uint32_t *)data)); break; diff --git a/tests/cram/test_blobmsg.t b/tests/cram/test_blobmsg.t index 0c192c5..b4d1431 100644 --- a/tests/cram/test_blobmsg.t +++ b/tests/cram/test_blobmsg.t @@ -10,8 +10,6 @@ check that blobmsg is producing expected results: 100 (i8) -128 (i8) 127 (i8) - -32768 (i16) - 32767 (i16) -2147483648 (i32) 2147483647 (i32) -9223372036854775808 (i64) @@ -26,8 +24,6 @@ check that blobmsg is producing expected results: \tpoo : 100 (i8) (esc) \tmoo-min : -128 (i8) (esc) \tmoo-max : 127 (i8) (esc) - \tbar-min : -32768 (i16) (esc) - \tbar-max : 32767 (i16) (esc) \tbaz-min : -2147483648 (i32) (esc) \tbaz-max : 2147483647 (i32) (esc) \ttaz-min : -9223372036854775808 (i64) (esc) @@ -44,8 +40,6 @@ check that blobmsg is producing expected results: 1 (i8) 1 (i8) 1 (i8) - -32768 (i32) - 32767 (i32) -2147483648 (i32) 2147483647 (i32) -9223372036854775808 (i64) @@ -77,8 +71,6 @@ check that blobmsg is producing expected results: 100 (i8) -128 (i8) 127 (i8) - -32768 (i16) - 32767 (i16) -2147483648 (i32) 2147483647 (i32) -9223372036854775808 (i64) @@ -93,8 +85,6 @@ check that blobmsg is producing expected results: \tpoo : 100 (i8) (esc) \tmoo-min : -128 (i8) (esc) \tmoo-max : 127 (i8) (esc) - \tbar-min : -32768 (i16) (esc) - \tbar-max : 32767 (i16) (esc) \tbaz-min : -2147483648 (i32) (esc) \tbaz-max : 2147483647 (i32) (esc) \ttaz-min : -9223372036854775808 (i64) (esc) @@ -144,8 +134,6 @@ check that blobmsg is producing expected results: 100 (i8) -128 (i8) 127 (i8) - -32768 (i16) - 32767 (i16) -2147483648 (i32) 2147483647 (i32) -9223372036854775808 (i64) @@ -160,8 +148,6 @@ check that blobmsg is producing expected results: \tpoo : 100 (i8) (esc) \tmoo-min : -128 (i8) (esc) \tmoo-max : 127 (i8) (esc) - \tbar-min : -32768 (i16) (esc) - \tbar-max : 32767 (i16) (esc) \tbaz-min : -2147483648 (i32) (esc) \tbaz-max : 2147483647 (i32) (esc) \ttaz-min : -9223372036854775808 (i64) (esc) @@ -211,8 +197,6 @@ check that blobmsg is producing expected results: 100 (i8) -128 (i8) 127 (i8) - -32768 (i16) - 32767 (i16) -2147483648 (i32) 2147483647 (i32) -9223372036854775808 (i64) @@ -227,8 +211,6 @@ check that blobmsg is producing expected results: \tpoo : 100 (i8) (esc) \tmoo-min : -128 (i8) (esc) \tmoo-max : 127 (i8) (esc) - \tbar-min : -32768 (i16) (esc) - \tbar-max : 32767 (i16) (esc) \tbaz-min : -2147483648 (i32) (esc) \tbaz-max : 2147483647 (i32) (esc) \ttaz-min : -9223372036854775808 (i64) (esc) diff --git a/tests/cram/test_blobmsg_types.t b/tests/cram/test_blobmsg_types.t index 190e1f2..8e3aa86 100644 --- a/tests/cram/test_blobmsg_types.t +++ b/tests/cram/test_blobmsg_types.t @@ -9,8 +9,6 @@ check that blobmsg is producing expected results: int64_min: -9223372036854775808 int32_max: 2147483647 int32_min: -2147483648 - int16_max: 32767 - int16_min: -32768 int8_max: 127 int8_min: -128 double_max: 1.797693e+308 @@ -21,8 +19,6 @@ check that blobmsg is producing expected results: int64_min: 9223372036854775808 int32_max: 2147483647 int32_min: 2147483648 - int16_max: 32767 - int16_min: 32768 int8_max: 127 int8_min: 128 double_max: 1.797693e+308 @@ -33,14 +29,12 @@ check that blobmsg is producing expected results: int64_min: -9223372036854775808 int32_max: 2147483647 int32_min: -2147483648 - int16_max: 32767 - int16_min: -32768 int8_max: 127 int8_min: -128 double_max: 1.797693e+308 double_min: 2.225074e-308 - [*] blobmsg to json: {"string":"Hello, world!","int64_max":9223372036854775807,"int64_min":-9223372036854775808,"int32_max":2147483647,"int32_min":-2147483648,"int16_max":32767,"int16_min":-32768,"int8_max":true,"int8_min":true,"double_max":179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000,"double_min":0.000000} + [*] blobmsg to json: {"string":"Hello, world!","int64_max":9223372036854775807,"int64_min":-9223372036854775808,"int32_max":2147483647,"int32_min":-2147483648,"int8_max":true,"int8_min":true,"double_max":179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000,"double_min":0.000000} [*] blobmsg from json: string: Hello, world! @@ -48,8 +42,6 @@ check that blobmsg is producing expected results: int64_min: -9223372036854775808 int32_max: 2147483647 int32_min: -2147483648 - int16_max: 32767 - int16_min: -32768 int8_max: 1 int8_min: 1 double_max: 1.797693e+308 @@ -61,8 +53,6 @@ check that blobmsg is producing expected results: int64_min: 9223372036854775808 int32_max: 2147483647 int32_min: 2147483648 - int16_max: 32767 - int16_min: 4294934528 int8_max: 1 int8_min: 1 double_max: 1.797693e+308 @@ -74,8 +64,6 @@ check that blobmsg is producing expected results: int64_min: -9223372036854775808 int32_max: 2147483647 int32_min: -2147483648 - int16_max: 32767 - int16_min: -32768 int8_max: 1 int8_min: 1 double_max: 1.797693e+308 diff --git a/tests/fuzz/test-fuzz.c b/tests/fuzz/test-fuzz.c index 026a3fd..e71c6a0 100644 --- a/tests/fuzz/test-fuzz.c +++ b/tests/fuzz/test-fuzz.c @@ -24,7 +24,6 @@ static void fuzz_blobmsg_parse(const uint8_t *data, size_t size) BLOBMSG_TYPE_STRING, BLOBMSG_TYPE_INT64, BLOBMSG_TYPE_INT32, - BLOBMSG_TYPE_INT16, BLOBMSG_TYPE_INT8, BLOBMSG_TYPE_DOUBLE, BLOBMSG_TYPE_TROUBLE, @@ -66,7 +65,6 @@ static void fuzz_blob_parse(const uint8_t *data, size_t size) FOO_ATTR_BINARY, FOO_ATTR_STRING, FOO_ATTR_INT8, - FOO_ATTR_INT16, FOO_ATTR_INT32, FOO_ATTR_INT64, FOO_ATTR_DOUBLE, @@ -79,7 +77,6 @@ static void fuzz_blob_parse(const uint8_t *data, size_t size) [FOO_ATTR_BINARY] = { .type = BLOB_ATTR_BINARY }, [FOO_ATTR_STRING] = { .type = BLOB_ATTR_STRING }, [FOO_ATTR_INT8] = { .type = BLOB_ATTR_INT8 }, - [FOO_ATTR_INT16] = { .type = BLOB_ATTR_INT16 }, [FOO_ATTR_INT32] = { .type = BLOB_ATTR_INT32 }, [FOO_ATTR_INT64] = { .type = BLOB_ATTR_INT64 }, [FOO_ATTR_DOUBLE] = { .type = BLOB_ATTR_DOUBLE }, diff --git a/tests/test-blobmsg-types.c b/tests/test-blobmsg-types.c index 4d77a27..fae4ebe 100644 --- a/tests/test-blobmsg-types.c +++ b/tests/test-blobmsg-types.c @@ -13,8 +13,6 @@ enum { FOO_INT64_MIN, FOO_INT32_MAX, FOO_INT32_MIN, - FOO_INT16_MAX, - FOO_INT16_MIN, FOO_INT8_MAX, FOO_INT8_MIN, FOO_DOUBLE_MAX, @@ -43,14 +41,6 @@ static const struct blobmsg_policy pol[] = { .name = "int32_min", .type = BLOBMSG_TYPE_INT32, }, - [FOO_INT16_MAX] = { - .name = "int16_max", - .type = BLOBMSG_TYPE_INT16, - }, - [FOO_INT16_MIN] = { - .name = "int16_min", - .type = BLOBMSG_TYPE_INT16, - }, [FOO_INT8_MAX] = { .name = "int8_max", .type = BLOBMSG_TYPE_INT8, @@ -90,14 +80,6 @@ static const struct blobmsg_policy pol_json[] = { .name = "int32_min", .type = BLOBMSG_TYPE_INT32, }, - [FOO_INT16_MAX] = { - .name = "int16_max", - .type = BLOBMSG_TYPE_INT32, - }, - [FOO_INT16_MIN] = { - .name = "int16_min", - .type = BLOBMSG_TYPE_INT32, - }, [FOO_INT8_MAX] = { .name = "int8_max", .type = BLOBMSG_TYPE_INT8, @@ -138,10 +120,6 @@ static void dump_message(struct blob_buf *buf) fprintf(stderr, "int32_max: %" PRId32 "\n", (int32_t)blobmsg_get_u32(tb[FOO_INT32_MAX])); if (tb[FOO_INT32_MIN]) fprintf(stderr, "int32_min: %" PRId32 "\n", (int32_t)blobmsg_get_u32(tb[FOO_INT32_MIN])); - if (tb[FOO_INT16_MAX]) - fprintf(stderr, "int16_max: %" PRId16 "\n", (int16_t)blobmsg_get_u16(tb[FOO_INT16_MAX])); - if (tb[FOO_INT16_MIN]) - fprintf(stderr, "int16_min: %" PRId16 "\n", (int16_t)blobmsg_get_u16(tb[FOO_INT16_MIN])); if (tb[FOO_INT8_MAX]) fprintf(stderr, "int8_max: %" PRId8 "\n", (int8_t)blobmsg_get_u8(tb[FOO_INT8_MAX])); if (tb[FOO_INT8_MIN]) @@ -170,10 +148,6 @@ static void dump_message_cast_u64(struct blob_buf *buf) fprintf(stderr, "int32_max: %" PRIu64 "\n", blobmsg_cast_u64(tb[FOO_INT32_MAX])); if (tb[FOO_INT32_MIN]) fprintf(stderr, "int32_min: %" PRIu64 "\n", blobmsg_cast_u64(tb[FOO_INT32_MIN])); - if (tb[FOO_INT16_MAX]) - fprintf(stderr, "int16_max: %" PRIu64 "\n", blobmsg_cast_u64(tb[FOO_INT16_MAX])); - if (tb[FOO_INT16_MIN]) - fprintf(stderr, "int16_min: %" PRIu64 "\n", blobmsg_cast_u64(tb[FOO_INT16_MIN])); if (tb[FOO_INT8_MAX]) fprintf(stderr, "int8_max: %" PRIu64 "\n", blobmsg_cast_u64(tb[FOO_INT8_MAX])); if (tb[FOO_INT8_MIN]) @@ -202,10 +176,6 @@ static void dump_message_cast_s64(struct blob_buf *buf) fprintf(stderr, "int32_max: %" PRId64 "\n", blobmsg_cast_s64(tb[FOO_INT32_MAX])); if (tb[FOO_INT32_MIN]) fprintf(stderr, "int32_min: %" PRId64 "\n", blobmsg_cast_s64(tb[FOO_INT32_MIN])); - if (tb[FOO_INT16_MAX]) - fprintf(stderr, "int16_max: %" PRId64 "\n", blobmsg_cast_s64(tb[FOO_INT16_MAX])); - if (tb[FOO_INT16_MIN]) - fprintf(stderr, "int16_min: %" PRId64 "\n", blobmsg_cast_s64(tb[FOO_INT16_MIN])); if (tb[FOO_INT8_MAX]) fprintf(stderr, "int8_max: %" PRId64 "\n", blobmsg_cast_s64(tb[FOO_INT8_MAX])); if (tb[FOO_INT8_MIN]) @@ -234,12 +204,6 @@ static void dump_message_json(struct blob_buf *buf) fprintf(stderr, "int32_max: %" PRId32 "\n", blobmsg_get_u32(tb[FOO_INT32_MAX])); if (tb[FOO_INT32_MIN]) fprintf(stderr, "int32_min: %" PRId32 "\n", blobmsg_get_u32(tb[FOO_INT32_MIN])); - /* u16 is unknown to json, retrieve as u32 */ - if (tb[FOO_INT16_MAX]) - fprintf(stderr, "int16_max: %" PRId32 "\n", blobmsg_get_u32(tb[FOO_INT16_MAX])); - /* u16 is unknown to json, retrieve as u32 */ - if (tb[FOO_INT16_MIN]) - fprintf(stderr, "int16_min: %" PRId32 "\n", blobmsg_get_u32(tb[FOO_INT16_MIN])); /* u8 is converted to boolean (true: all values != 0/false: value 0) in json */ if (tb[FOO_INT8_MAX]) fprintf(stderr, "int8_max: %" PRId8 "\n", blobmsg_get_u8(tb[FOO_INT8_MAX])); @@ -270,10 +234,6 @@ static void dump_message_cast_u64_json(struct blob_buf *buf) fprintf(stderr, "int32_max: %" PRIu64 "\n", blobmsg_cast_u64(tb[FOO_INT32_MAX])); if (tb[FOO_INT32_MIN]) fprintf(stderr, "int32_min: %" PRIu64 "\n", blobmsg_cast_u64(tb[FOO_INT32_MIN])); - if (tb[FOO_INT16_MAX]) - fprintf(stderr, "int16_max: %" PRIu64 "\n", blobmsg_cast_u64(tb[FOO_INT16_MAX])); - if (tb[FOO_INT16_MIN]) - fprintf(stderr, "int16_min: %" PRIu64 "\n", blobmsg_cast_u64(tb[FOO_INT16_MIN])); if (tb[FOO_INT8_MAX]) fprintf(stderr, "int8_max: %" PRIu64 "\n", blobmsg_cast_u64(tb[FOO_INT8_MAX])); if (tb[FOO_INT8_MIN]) @@ -302,10 +262,6 @@ static void dump_message_cast_s64_json(struct blob_buf *buf) fprintf(stderr, "int32_max: %" PRId64 "\n", blobmsg_cast_s64(tb[FOO_INT32_MAX])); if (tb[FOO_INT32_MIN]) fprintf(stderr, "int32_min: %" PRId64 "\n", blobmsg_cast_s64(tb[FOO_INT32_MIN])); - if (tb[FOO_INT16_MAX]) - fprintf(stderr, "int16_max: %" PRId64 "\n", blobmsg_cast_s64(tb[FOO_INT16_MAX])); - if (tb[FOO_INT16_MIN]) - fprintf(stderr, "int16_min: %" PRId64 "\n", blobmsg_cast_s64(tb[FOO_INT16_MIN])); if (tb[FOO_INT8_MAX]) fprintf(stderr, "int8_max: %" PRId64 "\n", blobmsg_cast_s64(tb[FOO_INT8_MAX])); if (tb[FOO_INT8_MIN]) @@ -324,8 +280,6 @@ fill_message(struct blob_buf *buf) blobmsg_add_u64(buf, "int64_min", INT64_MIN); blobmsg_add_u32(buf, "int32_max", INT32_MAX); blobmsg_add_u32(buf, "int32_min", INT32_MIN); - blobmsg_add_u16(buf, "int16_max", INT16_MAX); - blobmsg_add_u16(buf, "int16_min", INT16_MIN); blobmsg_add_u8(buf, "int8_max", INT8_MAX); blobmsg_add_u8(buf, "int8_min", INT8_MIN); blobmsg_add_double(buf, "double_max", DBL_MAX); diff --git a/tests/test-blobmsg.c b/tests/test-blobmsg.c index 2224853..04c5ca2 100644 --- a/tests/test-blobmsg.c +++ b/tests/test-blobmsg.c @@ -43,9 +43,6 @@ static void dump_attr_data(struct blob_attr *data, int indent, int next_indent) case BLOBMSG_TYPE_INT8: indent_printf(indent, "%d (i8)\n", (int8_t) blobmsg_get_u8(data)); break; - case BLOBMSG_TYPE_INT16: - indent_printf(indent, "%d (i16)\n", (int16_t) blobmsg_get_u16(data)); - break; case BLOBMSG_TYPE_INT32: indent_printf(indent, "%d (i32)\n", (int32_t) blobmsg_get_u32(data)); break; @@ -125,8 +122,6 @@ fill_message(struct blob_buf *buf) blobmsg_add_u8(buf, "poo", 100); blobmsg_add_u8(buf, "moo-min", INT8_MIN); blobmsg_add_u8(buf, "moo-max", INT8_MAX); - blobmsg_add_u16(buf, "bar-min", INT16_MIN); - blobmsg_add_u16(buf, "bar-max", INT16_MAX); blobmsg_add_u32(buf, "baz-min", INT32_MIN); blobmsg_add_u32(buf, "baz-max", INT32_MAX); blobmsg_add_u64(buf, "taz-min", INT64_MIN); @@ -139,8 +134,6 @@ fill_message(struct blob_buf *buf) blobmsg_add_u8(buf, NULL, 100); blobmsg_add_u8(buf, NULL, INT8_MIN); blobmsg_add_u8(buf, NULL, INT8_MAX); - blobmsg_add_u16(buf, NULL, INT16_MIN); - blobmsg_add_u16(buf, NULL, INT16_MAX); blobmsg_add_u32(buf, NULL, INT32_MIN); blobmsg_add_u32(buf, NULL, INT32_MAX); blobmsg_add_u64(buf, NULL, INT64_MIN); From 8e310ef832886754153733ffe928a2e597c533c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Mon, 10 Nov 2025 22:57:20 +0100 Subject: [PATCH 2/2] blobmsg: remove int8 support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit u8 has the same effective size as u32 so we can remove it to avoid a lot of compatibility mess and JSON conversion issues. Link: https://github.com/openwrt/libubox/pull/25 Signed-off-by: Álvaro Fernández Rojas --- blob.c | 4 +- blob.h | 20 +++---- blobmsg.c | 4 +- blobmsg.h | 18 ++----- blobmsg_json.c | 4 +- tests/cram/test_blobmsg.t | 94 +++++++++------------------------ tests/cram/test_blobmsg_types.t | 26 ++++----- tests/fuzz/test-fuzz.c | 6 +-- tests/test-blobmsg-types.c | 82 ++++++++++++++-------------- tests/test-blobmsg.c | 16 +++--- 10 files changed, 105 insertions(+), 169 deletions(-) diff --git a/blob.c b/blob.c index 179e35a..fa86605 100644 --- a/blob.c +++ b/blob.c @@ -191,7 +191,7 @@ blob_nest_end(struct blob_buf *buf, void *cookie) static const size_t blob_type_minlen[BLOB_ATTR_LAST] = { [BLOB_ATTR_STRING] = 1, - [BLOB_ATTR_INT8] = sizeof(uint8_t), + [BLOB_ATTR_BOOL] = sizeof(bool), [BLOB_ATTR_INT32] = sizeof(uint32_t), [BLOB_ATTR_INT64] = sizeof(uint64_t), [BLOB_ATTR_DOUBLE] = sizeof(double), @@ -205,7 +205,7 @@ blob_check_type(const void *ptr, unsigned int len, int type) if (type >= BLOB_ATTR_LAST) return false; - if (type >= BLOB_ATTR_INT8 && type <= BLOB_ATTR_INT64) { + if (type >= BLOB_ATTR_BOOL && type <= BLOB_ATTR_INT64) { if (len != blob_type_minlen[type]) return false; } else { diff --git a/blob.h b/blob.h index 0f71344..a61a344 100644 --- a/blob.h +++ b/blob.h @@ -35,7 +35,7 @@ enum { BLOB_ATTR_NESTED, BLOB_ATTR_BINARY, BLOB_ATTR_STRING, - BLOB_ATTR_INT8, + BLOB_ATTR_BOOL, __BLOB_ATTR_DEPRECATED_INT16, BLOB_ATTR_INT32, BLOB_ATTR_INT64, @@ -122,10 +122,10 @@ blob_pad_len(const struct blob_attr *attr) return len; } -static inline uint8_t -blob_get_u8(const struct blob_attr *attr) +static inline bool +blob_get_bool(const struct blob_attr *attr) { - return *((uint8_t *) attr->data); + return *((bool *) attr->data); } static inline uint32_t @@ -144,14 +144,9 @@ blob_get_u64(const struct blob_attr *attr) return tmp; } +#define blob_get_u8 blob_get_bool #define blob_get_u16 blob_get_u32 -static inline int8_t -blob_get_int8(const struct blob_attr *attr) -{ - return blob_get_u8(attr); -} - static inline int32_t blob_get_int32(const struct blob_attr *attr) { @@ -170,6 +165,7 @@ blob_get_string(const struct blob_attr *attr) return attr->data; } +#define blob_get_int8 blob_get_bool #define blob_get_int16 blob_get_int32 static inline struct blob_attr * @@ -201,7 +197,7 @@ blob_put_string(struct blob_buf *buf, int id, const char *str) } static inline struct blob_attr * -blob_put_u8(struct blob_buf *buf, int id, uint8_t val) +blob_put_bool(struct blob_buf *buf, int id, bool val) { return blob_put(buf, id, &val, sizeof(val)); } @@ -220,7 +216,7 @@ blob_put_u64(struct blob_buf *buf, int id, uint64_t val) return blob_put(buf, id, &val, sizeof(val)); } -#define blob_put_int8 blob_put_u8 +#define blob_put_int8 blob_put_bool #define blob_put_int16 blob_put_u32 #define blob_put_int32 blob_put_u32 #define blob_put_int64 blob_put_u64 diff --git a/blobmsg.c b/blobmsg.c index d49b80d..8502491 100644 --- a/blobmsg.c +++ b/blobmsg.c @@ -16,7 +16,7 @@ #include "blobmsg.h" static const int blob_type[__BLOBMSG_TYPE_LAST] = { - [BLOBMSG_TYPE_INT8] = BLOB_ATTR_INT8, + [BLOBMSG_TYPE_BOOL] = BLOB_ATTR_BOOL, [BLOBMSG_TYPE_INT32] = BLOB_ATTR_INT32, [BLOBMSG_TYPE_INT64] = BLOB_ATTR_INT64, [BLOBMSG_TYPE_DOUBLE] = BLOB_ATTR_DOUBLE, @@ -201,7 +201,7 @@ int blobmsg_parse(const struct blobmsg_policy *policy, int policy_len, if (policy[i].type == BLOBMSG_CAST_INT64 && (blob_id(attr) != BLOBMSG_TYPE_INT64 && blob_id(attr) != BLOBMSG_TYPE_INT32 && - blob_id(attr) != BLOBMSG_TYPE_INT8)) + blob_id(attr) != BLOBMSG_TYPE_BOOL)) continue; if (blobmsg_namelen(hdr) != pslen[i]) diff --git a/blobmsg.h b/blobmsg.h index 7b7469b..7c3e82c 100644 --- a/blobmsg.h +++ b/blobmsg.h @@ -30,8 +30,7 @@ enum blobmsg_type { BLOBMSG_TYPE_INT64, BLOBMSG_TYPE_INT32, __BLOBMSG_TYPE_DEPRECATED_INT16, - BLOBMSG_TYPE_INT8, - BLOBMSG_TYPE_BOOL = BLOBMSG_TYPE_INT8, + BLOBMSG_TYPE_BOOL, BLOBMSG_TYPE_DOUBLE, __BLOBMSG_TYPE_LAST, BLOBMSG_TYPE_LAST = __BLOBMSG_TYPE_LAST - 1, @@ -205,9 +204,9 @@ blobmsg_add_double(struct blob_buf *buf, const char *name, double val) } static inline int -blobmsg_add_u8(struct blob_buf *buf, const char *name, uint8_t val) +blobmsg_add_bool(struct blob_buf *buf, const char *name, bool val) { - return blobmsg_add_field(buf, BLOBMSG_TYPE_INT8, name, &val, 1); + return blobmsg_add_field(buf, BLOBMSG_TYPE_BOOL, name, &val, 1); } static inline int @@ -237,6 +236,7 @@ blobmsg_add_blob(struct blob_buf *buf, struct blob_attr *attr) blobmsg_data(attr), blobmsg_data_len(attr)); } +#define blobmsg_add_u8 blobmsg_add_bool #define blobmsg_add_u16 blobmsg_add_u32 void *blobmsg_open_nested(struct blob_buf *buf, const char *name, bool array); @@ -270,11 +270,6 @@ static inline int blobmsg_buf_init(struct blob_buf *buf) return blob_buf_init(buf, BLOBMSG_TYPE_TABLE); } -static inline uint8_t blobmsg_get_u8(struct blob_attr *attr) -{ - return *(uint8_t *) blobmsg_data(attr); -} - static inline bool blobmsg_get_bool(struct blob_attr *attr) { return *(uint8_t *) blobmsg_data(attr); @@ -293,6 +288,7 @@ static inline uint64_t blobmsg_get_u64(struct blob_attr *attr) return tmp; } +#define blobmsg_get_u8 blobmsg_get_bool #define blobmsg_get_u16 blobmsg_get_u32 static inline uint64_t blobmsg_cast_u64(struct blob_attr *attr) @@ -303,8 +299,6 @@ static inline uint64_t blobmsg_cast_u64(struct blob_attr *attr) tmp = blobmsg_get_u64(attr); else if (blobmsg_type(attr) == BLOBMSG_TYPE_INT32) tmp = blobmsg_get_u32(attr); - else if (blobmsg_type(attr) == BLOBMSG_TYPE_INT8) - tmp = blobmsg_get_u8(attr); return tmp; } @@ -317,8 +311,6 @@ static inline int64_t blobmsg_cast_s64(struct blob_attr *attr) tmp = blobmsg_get_u64(attr); else if (blobmsg_type(attr) == BLOBMSG_TYPE_INT32) tmp = (int32_t)blobmsg_get_u32(attr); - else if (blobmsg_type(attr) == BLOBMSG_TYPE_INT8) - tmp = (int8_t)blobmsg_get_u8(attr); return tmp; } diff --git a/blobmsg_json.c b/blobmsg_json.c index 9f11d59..f42762f 100644 --- a/blobmsg_json.c +++ b/blobmsg_json.c @@ -60,7 +60,7 @@ bool blobmsg_add_json_element(struct blob_buf *b, const char *name, json_object blobmsg_add_string(b, name, json_object_get_string(obj)); break; case json_type_boolean: - blobmsg_add_u8(b, name, json_object_get_boolean(obj)); + blobmsg_add_bool(b, name, json_object_get_boolean(obj)); break; case json_type_int: { int64_t i64 = json_object_get_int64(obj); @@ -248,7 +248,7 @@ static void blobmsg_format_element(struct strbuf *s, struct blob_attr *attr, boo snprintf(buf, sizeof(buf), "null"); break; case BLOBMSG_TYPE_BOOL: - snprintf(buf, sizeof(buf), "%s", *(uint8_t *)data ? "true" : "false"); + snprintf(buf, sizeof(buf), "%s", *(bool *)data ? "true" : "false"); break; case BLOBMSG_TYPE_INT32: snprintf(buf, sizeof(buf), "%" PRId32, (int32_t) be32_to_cpu(*(uint32_t *)data)); diff --git a/tests/cram/test_blobmsg.t b/tests/cram/test_blobmsg.t index b4d1431..e76cdbf 100644 --- a/tests/cram/test_blobmsg.t +++ b/tests/cram/test_blobmsg.t @@ -7,9 +7,7 @@ check that blobmsg is producing expected results: Message: Hello, world! List: { 0 (i8) - 100 (i8) - -128 (i8) - 127 (i8) + 1 (i8) -2147483648 (i32) 2147483647 (i32) -9223372036854775808 (i64) @@ -20,10 +18,8 @@ check that blobmsg is producing expected results: Testdata: { \tdbl-min : 0.000000 (dbl) (esc) \tdbl-max : 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000 (dbl) (esc) - \tfoo : 0 (i8) (esc) - \tpoo : 100 (i8) (esc) - \tmoo-min : -128 (i8) (esc) - \tmoo-max : 127 (i8) (esc) + \tbool-min : 0 (i8) (esc) + \tbool-max : 1 (i8) (esc) \tbaz-min : -2147483648 (i32) (esc) \tbaz-max : 2147483647 (i32) (esc) \ttaz-min : -9223372036854775808 (i64) (esc) @@ -31,15 +27,13 @@ check that blobmsg is producing expected results: \tworld : 2 (str) (esc) } - [*] blobmsg to json: {"message":"Hello, world!","testdata":{"dbl-min":0.000000,"dbl-max":179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000,"foo":false,"poo":true,"moo-min":true,"moo-max":true,"bar-min":-32768,"bar-max":32767,"baz-min":-2147483648,"baz-max":2147483647,"taz-min":-9223372036854775808,"taz-max":9223372036854775807,"world":"2"},"list":[false,true,true,true,-32768,32767,-2147483648,2147483647,-9223372036854775808,9223372036854775807,0.000000,179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000]} + [*] blobmsg to json: {"message":"Hello, world!","testdata":{"dbl-min":0.000000,"dbl-max":179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000,"bool-min":false,"bool-max":true,"baz-min":-2147483648,"baz-max":2147483647,"taz-min":-9223372036854775808,"taz-max":9223372036854775807,"world":"2"},"list":[false,true,-2147483648,2147483647,-9223372036854775808,9223372036854775807,0.000000,179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000]} [*] blobmsg from json: Message: Hello, world! List: { 0 (i8) 1 (i8) - 1 (i8) - 1 (i8) -2147483648 (i32) 2147483647 (i32) -9223372036854775808 (i64) @@ -50,12 +44,8 @@ check that blobmsg is producing expected results: Testdata: { \tdbl-min : 0.000000 (dbl) (esc) \tdbl-max : 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000 (dbl) (esc) - \tfoo : 0 (i8) (esc) - \tpoo : 1 (i8) (esc) - \tmoo-min : 1 (i8) (esc) - \tmoo-max : 1 (i8) (esc) - \tbar-min : -32768 (i32) (esc) - \tbar-max : 32767 (i32) (esc) + \tbool-min : 0 (i8) (esc) + \tbool-max : 1 (i8) (esc) \tbaz-min : -2147483648 (i32) (esc) \tbaz-max : 2147483647 (i32) (esc) \ttaz-min : -9223372036854775808 (i64) (esc) @@ -68,9 +58,7 @@ check that blobmsg is producing expected results: Message: Hello, world! List: { 0 (i8) - 100 (i8) - -128 (i8) - 127 (i8) + 1 (i8) -2147483648 (i32) 2147483647 (i32) -9223372036854775808 (i64) @@ -81,10 +69,8 @@ check that blobmsg is producing expected results: Testdata: { \tdbl-min : 0.000000 (dbl) (esc) \tdbl-max : 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000 (dbl) (esc) - \tfoo : 0 (i8) (esc) - \tpoo : 100 (i8) (esc) - \tmoo-min : -128 (i8) (esc) - \tmoo-max : 127 (i8) (esc) + \tbool-min : 0 (i8) (esc) + \tbool-max : 1 (i8) (esc) \tbaz-min : -2147483648 (i32) (esc) \tbaz-max : 2147483647 (i32) (esc) \ttaz-min : -9223372036854775808 (i64) (esc) @@ -92,17 +78,13 @@ check that blobmsg is producing expected results: \tworld : 2 (str) (esc) } - [*] blobmsg to json: {"message":"Hello, world!","testdata":{"dbl-min":0.000000,"dbl-max":179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000,"foo":false,"poo":true,"moo-min":true,"moo-max":true,"bar-min":-32768,"bar-max":32767,"baz-min":-2147483648,"baz-max":2147483647,"taz-min":-9223372036854775808,"taz-max":9223372036854775807,"world":"2"},"list":[false,true,true,true,-32768,32767,-2147483648,2147483647,-9223372036854775808,9223372036854775807,0.000000,179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000]} + [*] blobmsg to json: {"message":"Hello, world!","testdata":{"dbl-min":0.000000,"dbl-max":179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000,"bool-min":false,"bool-max":true,"baz-min":-2147483648,"baz-max":2147483647,"taz-min":-9223372036854775808,"taz-max":9223372036854775807,"world":"2"},"list":[false,true,-2147483648,2147483647,-9223372036854775808,9223372036854775807,0.000000,179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000]} [*] blobmsg from json: Message: Hello, world! List: { 0 (i8) 1 (i8) - 1 (i8) - 1 (i8) - -32768 (i32) - 32767 (i32) -2147483648 (i32) 2147483647 (i32) -9223372036854775808 (i64) @@ -113,12 +95,8 @@ check that blobmsg is producing expected results: Testdata: { \tdbl-min : 0.000000 (dbl) (esc) \tdbl-max : 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000 (dbl) (esc) - \tfoo : 0 (i8) (esc) - \tpoo : 1 (i8) (esc) - \tmoo-min : 1 (i8) (esc) - \tmoo-max : 1 (i8) (esc) - \tbar-min : -32768 (i32) (esc) - \tbar-max : 32767 (i32) (esc) + \tbool-min : 0 (i8) (esc) + \tbool-max : 1 (i8) (esc) \tbaz-min : -2147483648 (i32) (esc) \tbaz-max : 2147483647 (i32) (esc) \ttaz-min : -9223372036854775808 (i64) (esc) @@ -131,9 +109,7 @@ check that blobmsg is producing expected results: Message: Hello, world! List: { 0 (i8) - 100 (i8) - -128 (i8) - 127 (i8) + 1 (i8) -2147483648 (i32) 2147483647 (i32) -9223372036854775808 (i64) @@ -144,10 +120,8 @@ check that blobmsg is producing expected results: Testdata: { \tdbl-min : 0.000000 (dbl) (esc) \tdbl-max : 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000 (dbl) (esc) - \tfoo : 0 (i8) (esc) - \tpoo : 100 (i8) (esc) - \tmoo-min : -128 (i8) (esc) - \tmoo-max : 127 (i8) (esc) + \tbool-min : 0 (i8) (esc) + \tbool-max : 1 (i8) (esc) \tbaz-min : -2147483648 (i32) (esc) \tbaz-max : 2147483647 (i32) (esc) \ttaz-min : -9223372036854775808 (i64) (esc) @@ -155,17 +129,13 @@ check that blobmsg is producing expected results: \tworld : 2 (str) (esc) } - [*] blobmsg to json: {"message":"Hello, world!","testdata":{"dbl-min":0.000000,"dbl-max":179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000,"foo":false,"poo":true,"moo-min":true,"moo-max":true,"bar-min":-32768,"bar-max":32767,"baz-min":-2147483648,"baz-max":2147483647,"taz-min":-9223372036854775808,"taz-max":9223372036854775807,"world":"2"},"list":[false,true,true,true,-32768,32767,-2147483648,2147483647,-9223372036854775808,9223372036854775807,0.000000,179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000]} + [*] blobmsg to json: {"message":"Hello, world!","testdata":{"dbl-min":0.000000,"dbl-max":179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000,"bool-min":false,"bool-max":true,"baz-min":-2147483648,"baz-max":2147483647,"taz-min":-9223372036854775808,"taz-max":9223372036854775807,"world":"2"},"list":[false,true,-2147483648,2147483647,-9223372036854775808,9223372036854775807,0.000000,179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000]} [*] blobmsg from json: Message: Hello, world! List: { 0 (i8) 1 (i8) - 1 (i8) - 1 (i8) - -32768 (i32) - 32767 (i32) -2147483648 (i32) 2147483647 (i32) -9223372036854775808 (i64) @@ -176,12 +146,8 @@ check that blobmsg is producing expected results: Testdata: { \tdbl-min : 0.000000 (dbl) (esc) \tdbl-max : 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000 (dbl) (esc) - \tfoo : 0 (i8) (esc) - \tpoo : 1 (i8) (esc) - \tmoo-min : 1 (i8) (esc) - \tmoo-max : 1 (i8) (esc) - \tbar-min : -32768 (i32) (esc) - \tbar-max : 32767 (i32) (esc) + \tbool-min : 0 (i8) (esc) + \tbool-max : 1 (i8) (esc) \tbaz-min : -2147483648 (i32) (esc) \tbaz-max : 2147483647 (i32) (esc) \ttaz-min : -9223372036854775808 (i64) (esc) @@ -194,9 +160,7 @@ check that blobmsg is producing expected results: Message: Hello, world! List: { 0 (i8) - 100 (i8) - -128 (i8) - 127 (i8) + 1 (i8) -2147483648 (i32) 2147483647 (i32) -9223372036854775808 (i64) @@ -207,10 +171,8 @@ check that blobmsg is producing expected results: Testdata: { \tdbl-min : 0.000000 (dbl) (esc) \tdbl-max : 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000 (dbl) (esc) - \tfoo : 0 (i8) (esc) - \tpoo : 100 (i8) (esc) - \tmoo-min : -128 (i8) (esc) - \tmoo-max : 127 (i8) (esc) + \tbool-min : 0 (i8) (esc) + \tbool-max : 1 (i8) (esc) \tbaz-min : -2147483648 (i32) (esc) \tbaz-max : 2147483647 (i32) (esc) \ttaz-min : -9223372036854775808 (i64) (esc) @@ -218,17 +180,13 @@ check that blobmsg is producing expected results: \tworld : 2 (str) (esc) } - [*] blobmsg to json: {"message":"Hello, world!","testdata":{"dbl-min":0.000000,"dbl-max":179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000,"foo":false,"poo":true,"moo-min":true,"moo-max":true,"bar-min":-32768,"bar-max":32767,"baz-min":-2147483648,"baz-max":2147483647,"taz-min":-9223372036854775808,"taz-max":9223372036854775807,"world":"2"},"list":[false,true,true,true,-32768,32767,-2147483648,2147483647,-9223372036854775808,9223372036854775807,0.000000,179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000]} + [*] blobmsg to json: {"message":"Hello, world!","testdata":{"dbl-min":0.000000,"dbl-max":179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000,"bool-min":false,"bool-max":true,"baz-min":-2147483648,"baz-max":2147483647,"taz-min":-9223372036854775808,"taz-max":9223372036854775807,"world":"2"},"list":[false,true,-2147483648,2147483647,-9223372036854775808,9223372036854775807,0.000000,179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000]} [*] blobmsg from json: Message: Hello, world! List: { 0 (i8) 1 (i8) - 1 (i8) - 1 (i8) - -32768 (i32) - 32767 (i32) -2147483648 (i32) 2147483647 (i32) -9223372036854775808 (i64) @@ -239,12 +197,8 @@ check that blobmsg is producing expected results: Testdata: { \tdbl-min : 0.000000 (dbl) (esc) \tdbl-max : 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000 (dbl) (esc) - \tfoo : 0 (i8) (esc) - \tpoo : 1 (i8) (esc) - \tmoo-min : 1 (i8) (esc) - \tmoo-max : 1 (i8) (esc) - \tbar-min : -32768 (i32) (esc) - \tbar-max : 32767 (i32) (esc) + \tbool-min : 0 (i8) (esc) + \tbool-max : 1 (i8) (esc) \tbaz-min : -2147483648 (i32) (esc) \tbaz-max : 2147483647 (i32) (esc) \ttaz-min : -9223372036854775808 (i64) (esc) diff --git a/tests/cram/test_blobmsg_types.t b/tests/cram/test_blobmsg_types.t index 8e3aa86..3f5da4c 100644 --- a/tests/cram/test_blobmsg_types.t +++ b/tests/cram/test_blobmsg_types.t @@ -9,8 +9,8 @@ check that blobmsg is producing expected results: int64_min: -9223372036854775808 int32_max: 2147483647 int32_min: -2147483648 - int8_max: 127 - int8_min: -128 + bool_max: 1 + bool_min: 0 double_max: 1.797693e+308 double_min: 2.225074e-308 [*] blobmsg dump cast_u64: @@ -19,8 +19,8 @@ check that blobmsg is producing expected results: int64_min: 9223372036854775808 int32_max: 2147483647 int32_min: 2147483648 - int8_max: 127 - int8_min: 128 + bool_max: 1 + bool_min: 0 double_max: 1.797693e+308 double_min: 2.225074e-308 [*] blobmsg dump cast_s64: @@ -29,12 +29,12 @@ check that blobmsg is producing expected results: int64_min: -9223372036854775808 int32_max: 2147483647 int32_min: -2147483648 - int8_max: 127 - int8_min: -128 + bool_max: 1 + bool_min: 0 double_max: 1.797693e+308 double_min: 2.225074e-308 - [*] blobmsg to json: {"string":"Hello, world!","int64_max":9223372036854775807,"int64_min":-9223372036854775808,"int32_max":2147483647,"int32_min":-2147483648,"int8_max":true,"int8_min":true,"double_max":179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000,"double_min":0.000000} + [*] blobmsg to json: {"string":"Hello, world!","int64_max":9223372036854775807,"int64_min":-9223372036854775808,"int32_max":2147483647,"int32_min":-2147483648,"bool_max":true,"bool_min":false,"double_max":179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000,"double_min":0.000000} [*] blobmsg from json: string: Hello, world! @@ -42,8 +42,8 @@ check that blobmsg is producing expected results: int64_min: -9223372036854775808 int32_max: 2147483647 int32_min: -2147483648 - int8_max: 1 - int8_min: 1 + bool_max: 1 + bool_min: 0 double_max: 1.797693e+308 double_min: 0.000000e+00 @@ -53,8 +53,8 @@ check that blobmsg is producing expected results: int64_min: 9223372036854775808 int32_max: 2147483647 int32_min: 2147483648 - int8_max: 1 - int8_min: 1 + bool_max: 1 + bool_min: 0 double_max: 1.797693e+308 double_min: 0.000000e+00 @@ -64,7 +64,7 @@ check that blobmsg is producing expected results: int64_min: -9223372036854775808 int32_max: 2147483647 int32_min: -2147483648 - int8_max: 1 - int8_min: 1 + bool_max: 1 + bool_min: 0 double_max: 1.797693e+308 double_min: 0.000000e+00 diff --git a/tests/fuzz/test-fuzz.c b/tests/fuzz/test-fuzz.c index e71c6a0..d6f50f8 100644 --- a/tests/fuzz/test-fuzz.c +++ b/tests/fuzz/test-fuzz.c @@ -24,7 +24,7 @@ static void fuzz_blobmsg_parse(const uint8_t *data, size_t size) BLOBMSG_TYPE_STRING, BLOBMSG_TYPE_INT64, BLOBMSG_TYPE_INT32, - BLOBMSG_TYPE_INT8, + BLOBMSG_TYPE_BOOL, BLOBMSG_TYPE_DOUBLE, BLOBMSG_TYPE_TROUBLE, }; @@ -64,7 +64,7 @@ static void fuzz_blob_parse(const uint8_t *data, size_t size) FOO_ATTR_NESTED, FOO_ATTR_BINARY, FOO_ATTR_STRING, - FOO_ATTR_INT8, + FOO_ATTR_BOOL, FOO_ATTR_INT32, FOO_ATTR_INT64, FOO_ATTR_DOUBLE, @@ -76,7 +76,7 @@ static void fuzz_blob_parse(const uint8_t *data, size_t size) [FOO_ATTR_NESTED] = { .type = BLOB_ATTR_NESTED }, [FOO_ATTR_BINARY] = { .type = BLOB_ATTR_BINARY }, [FOO_ATTR_STRING] = { .type = BLOB_ATTR_STRING }, - [FOO_ATTR_INT8] = { .type = BLOB_ATTR_INT8 }, + [FOO_ATTR_BOOL] = { .type = BLOB_ATTR_BOOL }, [FOO_ATTR_INT32] = { .type = BLOB_ATTR_INT32 }, [FOO_ATTR_INT64] = { .type = BLOB_ATTR_INT64 }, [FOO_ATTR_DOUBLE] = { .type = BLOB_ATTR_DOUBLE }, diff --git a/tests/test-blobmsg-types.c b/tests/test-blobmsg-types.c index fae4ebe..26f1fe8 100644 --- a/tests/test-blobmsg-types.c +++ b/tests/test-blobmsg-types.c @@ -13,8 +13,8 @@ enum { FOO_INT64_MIN, FOO_INT32_MAX, FOO_INT32_MIN, - FOO_INT8_MAX, - FOO_INT8_MIN, + FOO_BOOL_MAX, + FOO_BOOL_MIN, FOO_DOUBLE_MAX, FOO_DOUBLE_MIN, __FOO_MAX @@ -41,13 +41,13 @@ static const struct blobmsg_policy pol[] = { .name = "int32_min", .type = BLOBMSG_TYPE_INT32, }, - [FOO_INT8_MAX] = { - .name = "int8_max", - .type = BLOBMSG_TYPE_INT8, + [FOO_BOOL_MAX] = { + .name = "bool_max", + .type = BLOBMSG_TYPE_BOOL, }, - [FOO_INT8_MIN] = { - .name = "int8_min", - .type = BLOBMSG_TYPE_INT8, + [FOO_BOOL_MIN] = { + .name = "bool_min", + .type = BLOBMSG_TYPE_BOOL, }, [FOO_DOUBLE_MAX] = { .name = "double_max", @@ -80,13 +80,13 @@ static const struct blobmsg_policy pol_json[] = { .name = "int32_min", .type = BLOBMSG_TYPE_INT32, }, - [FOO_INT8_MAX] = { - .name = "int8_max", - .type = BLOBMSG_TYPE_INT8, + [FOO_BOOL_MAX] = { + .name = "bool_max", + .type = BLOBMSG_TYPE_BOOL, }, - [FOO_INT8_MIN] = { - .name = "int8_min", - .type = BLOBMSG_TYPE_INT8, + [FOO_BOOL_MIN] = { + .name = "bool_min", + .type = BLOBMSG_TYPE_BOOL, }, [FOO_DOUBLE_MAX] = { .name = "double_max", @@ -120,10 +120,10 @@ static void dump_message(struct blob_buf *buf) fprintf(stderr, "int32_max: %" PRId32 "\n", (int32_t)blobmsg_get_u32(tb[FOO_INT32_MAX])); if (tb[FOO_INT32_MIN]) fprintf(stderr, "int32_min: %" PRId32 "\n", (int32_t)blobmsg_get_u32(tb[FOO_INT32_MIN])); - if (tb[FOO_INT8_MAX]) - fprintf(stderr, "int8_max: %" PRId8 "\n", (int8_t)blobmsg_get_u8(tb[FOO_INT8_MAX])); - if (tb[FOO_INT8_MIN]) - fprintf(stderr, "int8_min: %" PRId8 "\n", (int8_t)blobmsg_get_u8(tb[FOO_INT8_MIN])); + if (tb[FOO_BOOL_MAX]) + fprintf(stderr, "bool_max: %" PRIu8 "\n", (int8_t)blobmsg_get_bool(tb[FOO_BOOL_MAX])); + if (tb[FOO_BOOL_MIN]) + fprintf(stderr, "bool_min: %" PRIu8 "\n", (int8_t)blobmsg_get_bool(tb[FOO_BOOL_MIN])); if (tb[FOO_DOUBLE_MAX]) fprintf(stderr, "double_max: %e\n", blobmsg_get_double(tb[FOO_DOUBLE_MAX])); if (tb[FOO_DOUBLE_MIN]) @@ -148,10 +148,10 @@ static void dump_message_cast_u64(struct blob_buf *buf) fprintf(stderr, "int32_max: %" PRIu64 "\n", blobmsg_cast_u64(tb[FOO_INT32_MAX])); if (tb[FOO_INT32_MIN]) fprintf(stderr, "int32_min: %" PRIu64 "\n", blobmsg_cast_u64(tb[FOO_INT32_MIN])); - if (tb[FOO_INT8_MAX]) - fprintf(stderr, "int8_max: %" PRIu64 "\n", blobmsg_cast_u64(tb[FOO_INT8_MAX])); - if (tb[FOO_INT8_MIN]) - fprintf(stderr, "int8_min: %" PRIu64 "\n", blobmsg_cast_u64(tb[FOO_INT8_MIN])); + if (tb[FOO_BOOL_MAX]) + fprintf(stderr, "bool_max: %" PRIu8 "\n", blobmsg_get_bool(tb[FOO_BOOL_MAX])); + if (tb[FOO_BOOL_MIN]) + fprintf(stderr, "bool_min: %" PRIu8 "\n", blobmsg_get_bool(tb[FOO_BOOL_MIN])); if (tb[FOO_DOUBLE_MAX]) fprintf(stderr, "double_max: %e\n", blobmsg_get_double(tb[FOO_DOUBLE_MAX])); if (tb[FOO_DOUBLE_MIN]) @@ -176,10 +176,10 @@ static void dump_message_cast_s64(struct blob_buf *buf) fprintf(stderr, "int32_max: %" PRId64 "\n", blobmsg_cast_s64(tb[FOO_INT32_MAX])); if (tb[FOO_INT32_MIN]) fprintf(stderr, "int32_min: %" PRId64 "\n", blobmsg_cast_s64(tb[FOO_INT32_MIN])); - if (tb[FOO_INT8_MAX]) - fprintf(stderr, "int8_max: %" PRId64 "\n", blobmsg_cast_s64(tb[FOO_INT8_MAX])); - if (tb[FOO_INT8_MIN]) - fprintf(stderr, "int8_min: %" PRId64 "\n", blobmsg_cast_s64(tb[FOO_INT8_MIN])); + if (tb[FOO_BOOL_MAX]) + fprintf(stderr, "bool_max: %" PRIu8 "\n", blobmsg_get_bool(tb[FOO_BOOL_MAX])); + if (tb[FOO_BOOL_MIN]) + fprintf(stderr, "bool_min: %" PRIu8 "\n", blobmsg_get_bool(tb[FOO_BOOL_MIN])); if (tb[FOO_DOUBLE_MAX]) fprintf(stderr, "double_max: %e\n", blobmsg_get_double(tb[FOO_DOUBLE_MAX])); if (tb[FOO_DOUBLE_MIN]) @@ -204,12 +204,10 @@ static void dump_message_json(struct blob_buf *buf) fprintf(stderr, "int32_max: %" PRId32 "\n", blobmsg_get_u32(tb[FOO_INT32_MAX])); if (tb[FOO_INT32_MIN]) fprintf(stderr, "int32_min: %" PRId32 "\n", blobmsg_get_u32(tb[FOO_INT32_MIN])); - /* u8 is converted to boolean (true: all values != 0/false: value 0) in json */ - if (tb[FOO_INT8_MAX]) - fprintf(stderr, "int8_max: %" PRId8 "\n", blobmsg_get_u8(tb[FOO_INT8_MAX])); - /* u8 is converted to boolean (true: all values != 0/false: value 0) in json */ - if (tb[FOO_INT8_MIN]) - fprintf(stderr, "int8_min: %" PRId8 "\n", blobmsg_get_u8(tb[FOO_INT8_MIN])); + if (tb[FOO_BOOL_MAX]) + fprintf(stderr, "bool_max: %" PRIu8 "\n", blobmsg_get_bool(tb[FOO_BOOL_MAX])); + if (tb[FOO_BOOL_MIN]) + fprintf(stderr, "bool_min: %" PRIu8 "\n", blobmsg_get_bool(tb[FOO_BOOL_MIN])); if (tb[FOO_DOUBLE_MAX]) fprintf(stderr, "double_max: %e\n", blobmsg_get_double(tb[FOO_DOUBLE_MAX])); if (tb[FOO_DOUBLE_MIN]) @@ -234,10 +232,10 @@ static void dump_message_cast_u64_json(struct blob_buf *buf) fprintf(stderr, "int32_max: %" PRIu64 "\n", blobmsg_cast_u64(tb[FOO_INT32_MAX])); if (tb[FOO_INT32_MIN]) fprintf(stderr, "int32_min: %" PRIu64 "\n", blobmsg_cast_u64(tb[FOO_INT32_MIN])); - if (tb[FOO_INT8_MAX]) - fprintf(stderr, "int8_max: %" PRIu64 "\n", blobmsg_cast_u64(tb[FOO_INT8_MAX])); - if (tb[FOO_INT8_MIN]) - fprintf(stderr, "int8_min: %" PRIu64 "\n", blobmsg_cast_u64(tb[FOO_INT8_MIN])); + if (tb[FOO_BOOL_MAX]) + fprintf(stderr, "bool_max: %" PRIu8 "\n", blobmsg_get_bool(tb[FOO_BOOL_MAX])); + if (tb[FOO_BOOL_MIN]) + fprintf(stderr, "bool_min: %" PRIu8 "\n", blobmsg_get_bool(tb[FOO_BOOL_MIN])); if (tb[FOO_DOUBLE_MAX]) fprintf(stderr, "double_max: %e\n", blobmsg_get_double(tb[FOO_DOUBLE_MAX])); if (tb[FOO_DOUBLE_MIN]) @@ -262,10 +260,10 @@ static void dump_message_cast_s64_json(struct blob_buf *buf) fprintf(stderr, "int32_max: %" PRId64 "\n", blobmsg_cast_s64(tb[FOO_INT32_MAX])); if (tb[FOO_INT32_MIN]) fprintf(stderr, "int32_min: %" PRId64 "\n", blobmsg_cast_s64(tb[FOO_INT32_MIN])); - if (tb[FOO_INT8_MAX]) - fprintf(stderr, "int8_max: %" PRId64 "\n", blobmsg_cast_s64(tb[FOO_INT8_MAX])); - if (tb[FOO_INT8_MIN]) - fprintf(stderr, "int8_min: %" PRId64 "\n", blobmsg_cast_s64(tb[FOO_INT8_MIN])); + if (tb[FOO_BOOL_MAX]) + fprintf(stderr, "bool_max: %" PRIu8 "\n", blobmsg_get_bool(tb[FOO_BOOL_MAX])); + if (tb[FOO_BOOL_MIN]) + fprintf(stderr, "bool_min: %" PRIu8 "\n", blobmsg_get_bool(tb[FOO_BOOL_MIN])); if (tb[FOO_DOUBLE_MAX]) fprintf(stderr, "double_max: %e\n", blobmsg_get_double(tb[FOO_DOUBLE_MAX])); if (tb[FOO_DOUBLE_MIN]) @@ -280,8 +278,8 @@ fill_message(struct blob_buf *buf) blobmsg_add_u64(buf, "int64_min", INT64_MIN); blobmsg_add_u32(buf, "int32_max", INT32_MAX); blobmsg_add_u32(buf, "int32_min", INT32_MIN); - blobmsg_add_u8(buf, "int8_max", INT8_MAX); - blobmsg_add_u8(buf, "int8_min", INT8_MIN); + blobmsg_add_bool(buf, "bool_max", true); + blobmsg_add_bool(buf, "bool_min", false); blobmsg_add_double(buf, "double_max", DBL_MAX); blobmsg_add_double(buf, "double_min", DBL_MIN); } diff --git a/tests/test-blobmsg.c b/tests/test-blobmsg.c index 04c5ca2..c6b3aa5 100644 --- a/tests/test-blobmsg.c +++ b/tests/test-blobmsg.c @@ -40,8 +40,8 @@ static void dump_attr_data(struct blob_attr *data, int indent, int next_indent) case BLOBMSG_TYPE_STRING: indent_printf(indent, "%s (str)\n", blobmsg_get_string(data)); break; - case BLOBMSG_TYPE_INT8: - indent_printf(indent, "%d (i8)\n", (int8_t) blobmsg_get_u8(data)); + case BLOBMSG_TYPE_BOOL: + indent_printf(indent, "%d (i8)\n", (int8_t) blobmsg_get_bool(data)); break; case BLOBMSG_TYPE_INT32: indent_printf(indent, "%d (i32)\n", (int32_t) blobmsg_get_u32(data)); @@ -118,10 +118,8 @@ fill_message(struct blob_buf *buf) tbl = blobmsg_open_table(buf, "testdata"); blobmsg_add_double(buf, "dbl-min", DBL_MIN); blobmsg_add_double(buf, "dbl-max", DBL_MAX); - blobmsg_add_u8(buf, "foo", 0); - blobmsg_add_u8(buf, "poo", 100); - blobmsg_add_u8(buf, "moo-min", INT8_MIN); - blobmsg_add_u8(buf, "moo-max", INT8_MAX); + blobmsg_add_bool(buf, "bool-min", false); + blobmsg_add_bool(buf, "bool-max", true); blobmsg_add_u32(buf, "baz-min", INT32_MIN); blobmsg_add_u32(buf, "baz-max", INT32_MAX); blobmsg_add_u64(buf, "taz-min", INT64_MIN); @@ -130,10 +128,8 @@ fill_message(struct blob_buf *buf) blobmsg_close_table(buf, tbl); tbl = blobmsg_open_array(buf, "list"); - blobmsg_add_u8(buf, NULL, 0); - blobmsg_add_u8(buf, NULL, 100); - blobmsg_add_u8(buf, NULL, INT8_MIN); - blobmsg_add_u8(buf, NULL, INT8_MAX); + blobmsg_add_bool(buf, NULL, false); + blobmsg_add_bool(buf, NULL, true); blobmsg_add_u32(buf, NULL, INT32_MIN); blobmsg_add_u32(buf, NULL, INT32_MAX); blobmsg_add_u64(buf, NULL, INT64_MIN);