Skip to content

Commit

Permalink
Fix malformed json on empty row print (merbanan#2588)
Browse files Browse the repository at this point in the history
Fix the the output to "{0}0" in case of an empty row.
  • Loading branch information
atlanticn authored Aug 5, 2023
1 parent bdd7933 commit fc727b3
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 fc727b3

Please sign in to comment.