howerj/dbcc

Unused code generation when message length is 0

izcet opened this issue · 1 comments

izcet commented

I found this bug with the following entry in a .dbc (modified for simplicity and privacy)

BO_ 42 MESSAGE_NAME: 0 MESSAGE_SENDER
 SG_ Signal_Name : 0|3@0+ (1,0) [0|7] "" DBG

which generates the following code

int unpack_can_0xc0000000_MESSAGE_NAME(can_0xc0000000_MESSAGE_NAME_t *unpack, uint64_t data, uint8_t dlc)
{
	register uint64_t x;
	register uint64_t m = reverse_byte_order(data);
	
	if(dlc < 0)
		return -1;
...

Which, when compiled with -Wall -Werror -Wextra throws the following error

dbc_file.c:123:9: error: comparison is always false due to limited range of data type [-Werror=type-limits]
  if(dlc < 0)
         ^

because dlc is of type unsigned.

The bug is not mission critical, removing the two offending lines and adding (void)dbc; silences the compiler warnings.

I don't yet know why the .dbc file has the entry with the 0 length message, or what the significance of that is (I'm new to DBC/CAN myself)

Hello! Thanks for the report and the example. The latest commit should have fixed this.

It is valid for a message to have a DLC of zero, but is equally likely to be a mistake. Perhaps it is being used to wake up receiving unit? Although the message having a DLC of zero and a signal to decode with does not strictly make sense, but it is a valid DBC file.

Let me know if you have any other problems.

Thanks,
Richard Howe