diff options
author | Sharvil Nanavati <sharvil@google.com> | 2015-04-07 23:22:08 -0700 |
---|---|---|
committer | Andre Eisenbach <eisenbach@google.com> | 2015-04-08 23:34:51 +0000 |
commit | 564697357d3041d8977d98e9680c09f1735be249 (patch) | |
tree | 344b150710b4a7b0c2a8caed4a3ea8e19f39df07 /doc | |
parent | d768767c33bf9c1330c01b04a8f308f5f174d0bf (diff) | |
download | android_system_bt-564697357d3041d8977d98e9680c09f1735be249.tar.gz android_system_bt-564697357d3041d8977d98e9680c09f1735be249.tar.bz2 android_system_bt-564697357d3041d8977d98e9680c09f1735be249.zip |
Add a section on assertions to the style guide.
Change-Id: I5627b5b2d6b25f0472c53b8150b14bab79b200c3
Diffstat (limited to 'doc')
-rw-r--r-- | doc/style_guide.md | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/doc/style_guide.md b/doc/style_guide.md index d62d2902e..e08be0a4a 100644 --- a/doc/style_guide.md +++ b/doc/style_guide.md @@ -168,6 +168,25 @@ routines and objects returned from those functions must be freed with the corresponding `*_free` function. For example, list objects returned from `list_new` should be freed with `list_free` and no other freeing routine. +### Asserts +Use `assert` liberally throughout the code to enforce invariants. Assertions +should not have any side-effects and should be used to detect programming logic +errors. + +At minimum, every function should assert expectations on its arguments. The +following example demonstrates the kinds of assertions one should make on +function arguments. +``` + size_t open_and_read_file(const char *filename, void *target_buffer, size_t max_bytes) { + assert(filename != NULL); + assert(filename[0] != '\0'); + assert(target_buffer != NULL); + assert(max_bytes > 0); + + // function implementation begins here + } +``` + ## Header files In general, every source file (`.c` or `.cpp`) in a `src/` directory should have a corresponding header (`.h`) in the `include/` directory. |