Message ID | 20210226192420.4553-1-ps.report@gmx.net |
---|---|
State | Accepted |
Delegated to: | Daniel Golle |
Headers | show |
Series | [v2] libubox: fix BLOBMSG_CAST_INT64 (do not override BLOBMSG_TYPE_DOUBLE) | expand |
Peter Seiderer <ps.report@gmx.net> [2021-02-26 20:24:20]: Hi, > Commit 9e52171 ('blobmsg: introduce BLOBMSG_CAST_INT64') broke > blobmsg_parse() for BLOBMSG_TYPE_DOUBLE. > > This is because the enum definition leads to the following double > define for BLOBMSG_CAST_INT64/BLOBMSG_TYPE_DOUBLE as value 8. > > Tested with: > > $ cat test-enum-001.c there is bunch of test cases already and I think, that it would make sense to simply extend the existing one, like for example tests/test-blobmsg.c in order to prevent future regressions as the CI checks are run after every push and since today daily as well. You can enable unit testing with `UNIT_TESTING=on` CMake variable, for example: mkdir build cmake -S $(pwd) -B $(pwd)/build -DUNIT_TESTING=1 make Thanks! Cheers, Petr
diff --git a/blobmsg.h b/blobmsg.h index 4a151c7..1f0634d 100644 --- a/blobmsg.h +++ b/blobmsg.h @@ -31,11 +31,11 @@ enum blobmsg_type { BLOBMSG_TYPE_INT32, BLOBMSG_TYPE_INT16, BLOBMSG_TYPE_INT8, + BLOBMSG_TYPE_BOOL = BLOBMSG_TYPE_INT8, BLOBMSG_TYPE_DOUBLE, __BLOBMSG_TYPE_LAST, BLOBMSG_TYPE_LAST = __BLOBMSG_TYPE_LAST - 1, - BLOBMSG_TYPE_BOOL = BLOBMSG_TYPE_INT8, - BLOBMSG_CAST_INT64, + BLOBMSG_CAST_INT64 = __BLOBMSG_TYPE_LAST, }; struct blobmsg_hdr {
Commit 9e52171 ('blobmsg: introduce BLOBMSG_CAST_INT64') broke blobmsg_parse() for BLOBMSG_TYPE_DOUBLE. This is because the enum definition leads to the following double define for BLOBMSG_CAST_INT64/BLOBMSG_TYPE_DOUBLE as value 8. Tested with: $ cat test-enum-001.c #include <stdio.h> enum blobmsg_type { BLOBMSG_TYPE_UNSPEC, BLOBMSG_TYPE_ARRAY, BLOBMSG_TYPE_TABLE, BLOBMSG_TYPE_STRING, BLOBMSG_TYPE_INT64, BLOBMSG_TYPE_INT32, BLOBMSG_TYPE_INT16, BLOBMSG_TYPE_INT8, BLOBMSG_TYPE_DOUBLE, __BLOBMSG_TYPE_LAST, BLOBMSG_TYPE_LAST = __BLOBMSG_TYPE_LAST - 1, BLOBMSG_TYPE_BOOL = BLOBMSG_TYPE_INT8, BLOBMSG_CAST_INT64, }; int main(int artc, char* argv[]) { printf("BLOBMSG_TYPE_UNSPEC: %d\n", BLOBMSG_TYPE_UNSPEC); printf("BLOBMSG_TYPE_ARRAY: %d\n", BLOBMSG_TYPE_ARRAY); printf("BLOBMSG_TYPE_TABLE: %d\n", BLOBMSG_TYPE_TABLE); printf("BLOBMSG_TYPE_STRING: %d\n", BLOBMSG_TYPE_STRING); printf("BLOBMSG_TYPE_INT64: %d\n", BLOBMSG_TYPE_INT64); printf("BLOBMSG_TYPE_INT32: %d\n", BLOBMSG_TYPE_INT32); printf("BLOBMSG_TYPE_INT16: %d\n", BLOBMSG_TYPE_INT16); printf("BLOBMSG_TYPE_INT8: %d\n", BLOBMSG_TYPE_INT8); printf("BLOBMSG_TYPE_DOUBLE: %d\n", BLOBMSG_TYPE_DOUBLE); printf("__BLOBMSG_TYPE_LAST: %d\n", __BLOBMSG_TYPE_LAST); printf("BLOBMSG_TYPE_LAST: %d\n", BLOBMSG_TYPE_LAST); printf("BLOBMSG_TYPE_BOOL: %d\n", BLOBMSG_TYPE_BOOL); printf("BLOBMSG_CAST_INT64: %d\n", BLOBMSG_CAST_INT64); return 0; } $ gcc test-enum-001.c $ ./a.out BLOBMSG_TYPE_UNSPEC: 0 BLOBMSG_TYPE_ARRAY: 1 BLOBMSG_TYPE_TABLE: 2 BLOBMSG_TYPE_STRING: 3 BLOBMSG_TYPE_INT64: 4 BLOBMSG_TYPE_INT32: 5 BLOBMSG_TYPE_INT16: 6 BLOBMSG_TYPE_INT8: 7 BLOBMSG_TYPE_DOUBLE: 8 __BLOBMSG_TYPE_LAST: 9 BLOBMSG_TYPE_LAST: 8 BLOBMSG_TYPE_BOOL: 7 BLOBMSG_CAST_INT64: 8 Fix this by changing the enum defintion to assign BLOBMSG_CAST_INT64 to the unique value 9. Signed-off-by: Peter Seiderer <ps.report@gmx.net> --- Changes v1 -> v2: - re-send after subscribing to the mailing list - change patch subject prefix from blobmsg to libubox --- blobmsg.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)