Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error checking in the command encoder. #1913

Merged

Conversation

bzbarsky-apple
Copy link
Contributor

There are actually two changes here:

  1. Improve the error checking so that we correctly check that the
    buffer actually has enough space when writing a multibyte value.

  2. Introduce a way to ask the encoder how much space it needs to
    encode a given APS frame.

Fixes #1644

Problem

The error checking in the command encoder doesn't work correctly when encoding multibyte values

Summary of Changes

Fix the error checking to correctly check that we have enough space.

{
return size;
}
#define TRY_WRITE(dataItem) \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a generic method for interfacing with buffers? Having proper methods for interfacing with buffers may be a better solution than a locally defined macro

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't found one so far, but if we do, I'm happy to use it.

Note that this stuff is all still throwaway code pending whatever our real encoder will be; I really needed the "measure the size" aspect now, and adding it this way was simpler than keeping the existing structure of the code and adding lots of null-checks on buffer...

Also note that there is more work to be done here, e.g. to fix #1632

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something that works on top of PacketBuffer would be welcome. something that has a "measure" form would be ideal.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just added BufBound, which might help here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd need to switch this file to C++ to use that. Which might be fine as long as we keep the entrypoint APIs extern C.... I can rebase on top of your change once it lands as desired, and make that modification.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, yeah. I was thinking that we probably want to just make all these files C++ and fix any void* stuff

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, #1629 tracks the void* bits.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#2073 now tracks using BufBound here.

There are actually two changes here:

1) Improve the error checking so that we correctly check that the
   buffer actually has enough space when writing a multibyte value.

2) Introduce a way to ask the encoder how much space it needs to
   encode a given APS frame.

Fixes project-chip#1644
@bzbarsky-apple bzbarsky-apple force-pushed the encoder-fix-error-checking branch from fa5dcc1 to 8ef4108 Compare July 31, 2020 20:37
@github-actions
Copy link

Size increase report for "gn_nrf-example-build"

File Section File VM
Full report output
BLOAT REPORT

Files found only in the build output:
    report.csv


@github-actions
Copy link

Size increase report for "gn_linux-example-build"

File Section File VM
Full report output
BLOAT REPORT

Files found only in the build output:
    report.csv


@github-actions
Copy link

Size increase report for "nrf-example-build"

File Section File VM
Full report output
BLOAT REPORT

Files found only in the build output:
    report.csv

Comparing ./master_artifact/chip-nrf52840-lock-example.out and ./pull_artifact/chip-nrf52840-lock-example.out:

sections,vmsize,filesize


@github-actions
Copy link

Size increase report for "nrfconnect-example-build"

File Section File VM
Full report output
BLOAT REPORT

Files found only in the build output:
    report.csv

Comparing ./master_artifact/chip-nrf52840-lock-example.elf and ./pull_artifact/chip-nrf52840-lock-example.elf:

sections,vmsize,filesize


@github-actions
Copy link

Size increase report for "linux-example-build"

File Section File VM
chip-standalone-demo.out .text 48 48
chip-standalone-demo.out .eh_frame 40 40
chip-standalone-demo.out .eh_frame_hdr 8 8
Full report output
BLOAT REPORT

Files found only in the build output:
    report.csv

Comparing ./master_artifact/chip-standalone-demo.out and ./pull_artifact/chip-standalone-demo.out:

sections,vmsize,filesize
.debug_info,0,700
.debug_line,0,540
.debug_str,0,524
.debug_loc,0,410
.debug_ranges,0,80
.debug_abbrev,0,76
.debug_macro,0,70
.text,48,48
.eh_frame,40,40
.symtab,0,24
.strtab,0,17
.debug_aranges,0,16
.eh_frame_hdr,8,8
[Unmapped],0,-97


@github-actions
Copy link

Size increase report for "esp32-example-build"

File Section File VM
Full report output
BLOAT REPORT

Files found only in the build output:
    report.csv

Comparing ./master_artifact/chip-wifi-echo.elf and ./pull_artifact/chip-wifi-echo.elf:

sections,vmsize,filesize


@woody-apple
Copy link
Contributor

@jelderton @andy31415 ?

@woody-apple woody-apple merged commit 8e03d28 into project-chip:master Aug 3, 2020
@bzbarsky-apple bzbarsky-apple deleted the encoder-fix-error-checking branch August 4, 2020 02:38
chirag-silabs pushed a commit to rosahay-silabs/connectedhomeip that referenced this pull request Jul 15, 2024
…dio after creating a solution

Merge in WMN_TOOLS/matter from feature/solutions_seq_templates to silabs_slc_1.3

Squashed commit of the following:

commit 806440fda12d0a727f41efe549ebfa771be9619a
Author: Sarthak Shaha <[email protected]>
Date:   Tue May 28 15:06:53 2024 -0400

    rebase

commit 97b7b05729b7aa7cf2ffd3f5c108d1829433aab9
Author: Sarthak Shaha <[email protected]>
Date:   Tue May 28 13:47:10 2024 -0400

    fix to show project.slcp first in studio after creating a solution
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix error checking in encoder.c/decoder.c
6 participants