# HG changeset patch # User Edouard Tisserant # Date 1726740413 -7200 # Node ID 9e4a3a3ea5c020a7c4c352f91ac56b890af9d6b0 # Parent ab96d56f9ae93104f427f3946de2ce4abe747e04 MQTT: fix invocation of json_scanf (use pointers, not values...) diff -r ab96d56f9ae9 -r 9e4a3a3ea5c0 mqtt/mqtt_template.c --- a/mqtt/mqtt_template.c Thu Sep 19 12:05:35 2024 +0200 +++ b/mqtt/mqtt_template.c Thu Sep 19 12:06:53 2024 +0200 @@ -74,15 +74,20 @@ #define format_SIMPLE(C_type, name, _A) #name " : " format_##C_type #define format_OBJECT(C_type, name, _A) #name " : {{ " TYPE_##C_type(format, _A) " }}" -#define arg_separator , - -#define arg_SIMPLE(C_type, name, data_ptr) data_ptr->name -#define arg_OBJECT(C_type, name, data_ptr) TYPE_##C_type(arg, (&data_ptr->name)) +#define scanf_args_separator , + +#define scanf_args_SIMPLE(C_type, name, data_ptr) &data_ptr->name +#define scanf_args_OBJECT(C_type, name, data_ptr) TYPE_##C_type(scanf_args, (&data_ptr->name)) + +#define printf_args_separator , + +#define printf_args_SIMPLE(C_type, name, data_ptr) data_ptr->name +#define printf_args_OBJECT(C_type, name, data_ptr) TYPE_##C_type(printf_args, (&data_ptr->name)) #define DECL_JSON_INPUT(C_type, c_loc_name) \ int json_parse_##c_loc_name(char *json, const int len, void *void_ptr) {{ \ C_type *struct_ptr = (C_type *)void_ptr; \ - return json_scanf(json, len, "{{" TYPE_##C_type(format,) "}}", TYPE_##C_type(arg, struct_ptr)); \ + return json_scanf(json, len, "{{" TYPE_##C_type(format,) "}}", TYPE_##C_type(scanf_args, struct_ptr)); \ }} /* Pre-allocated json output buffer for json_printf */ @@ -93,7 +98,7 @@ #define DECL_JSON_OUTPUT(C_type, c_loc_name) \ int json_gen_##c_loc_name(C_type *struct_ptr) {{ \ struct json_out out = JSON_OUT_BUF(json_out_buf, json_out_size); \ - json_out_len = json_printf(&out, "{{" TYPE_##C_type(format,) "}}", TYPE_##C_type(arg, struct_ptr)); \ + json_out_len = json_printf(&out, "{{" TYPE_##C_type(format,) "}}", TYPE_##C_type(printf_args, struct_ptr)); \ if(json_out_len > json_out_size){{ \ json_out_len = 0; \ return -EOVERFLOW; \