libubox: fix BLOBMSG_CAST_INT64 (do not override BLOBMSG_TYPE_DOUBLE)

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>
This commit is contained in:
Peter Seiderer 2021-02-26 20:24:20 +01:00 committed by Daniel Golle
parent 5bc0146a1d
commit 2e52c7e9a9

View file

@ -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 {