libubox: fix BLOBMSG_CAST_INT64 (do not override BLOBMSG_TYPE_DOUBLE)
authorPeter Seiderer <ps.report@gmx.net>
Fri, 26 Feb 2021 19:24:20 +0000 (20:24 +0100)
committerDaniel Golle <daniel@makrotopia.org>
Tue, 2 Mar 2021 12:06:24 +0000 (12:06 +0000)
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>
blobmsg.h

index 4a151c717284a4821fdb92b35665fca80ac7d102..1f0634d8d066a54b999ee0368ba589299c50e8fe 100644 (file)
--- 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 {