Skip to content

Commit

Permalink
fix malformed json for empty row {0} to "{0}0"
Browse files Browse the repository at this point in the history
When using
rtl_433 -F json -X 'n=raw,m=FSK_MC_ZEROBIT'
sometimes rtl_433 outputs json containing an invalid dictionary:
"codes" : [{0}]

Fix the source to output "{0}0" in case of an empty row.
  • Loading branch information
atlanticn committed Aug 5, 2023
1 parent bdd7933 commit 68c43d9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/decoder_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ static char *bitrow_asprint_code(uint8_t const *bitrow, unsigned bit_len)
// remove last nibble if needed
row_bytes[2 * (bit_len + 3) / 8] = '\0';

// print at least one '0'
if (bit_len == 0) {
sprintf(row_bytes, "0");
}

// a simple bitrow representation
row_code = malloc(8 + bit_len / 4 + 1); // "{nnnn}..\0"
if (!row_code) {
Expand Down
5 changes: 5 additions & 0 deletions src/devices/flex.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@ static int flex_callback(r_device *decoder, bitbuffer_t *bitbuffer)
// add a data line for each getter
render_getters(row_data[i], bitbuffer->bb[i], params);

// print at least one '0'
if (row_bytes[0] == '\0') {
sprintf(row_bytes, "0");
}

// a simpler representation for csv output
row_codes[i] = malloc(8 + bitbuffer->bits_per_row[i] / 4 + 1); // "{nnnn}..\0"
if (!row_codes[i])
Expand Down

0 comments on commit 68c43d9

Please sign in to comment.