From 44fa4a0d43a4026a091f82a055c649aa7c922706 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Fri, 26 Feb 2016 09:18:24 +0100 Subject: workflow: Update guidelines on use of pointers the void * returned by malloc should not be explicitly cast when checking pointers for validity, only use (ptr == NULL) --- doc/workflow.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/doc/workflow.txt b/doc/workflow.txt index ee4afb95..e48375bb 100644 --- a/doc/workflow.txt +++ b/doc/workflow.txt @@ -21,6 +21,14 @@ int * a; instead of int *a; +- don't explicitly cast malloc, but do + +your * = malloc (sizeof *your * len); + +- when checking for invalid pointers use + +if (ptr == NULL), instead of if (!ptr) + 3. Development workflow Git is used as a version tooling for the code. Releases are identified -- cgit v1.2.3 From bb1d3fd141c33a98137edd9261a9adb9ea1d3753 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Fri, 26 Feb 2016 14:57:24 +0100 Subject: doc: updated workflow and corrected all mallocs lib/du_buff contained casted malloc's. --- doc/workflow.txt | 14 +++++++++++--- src/lib/du_buff.c | 6 +++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/doc/workflow.txt b/doc/workflow.txt index e48375bb..02d13f64 100644 --- a/doc/workflow.txt +++ b/doc/workflow.txt @@ -21,13 +21,21 @@ int * a; instead of int *a; -- don't explicitly cast malloc, but do +- Don't explicitly cast malloc, but do your * = malloc (sizeof *your * len); -- when checking for invalid pointers use +or -if (ptr == NULL), instead of if (!ptr) +your * = malloc (sizeof (*your) * len); + +- When checking for invalid pointers use + +if (ptr == NULL) + +instead of + +if (!ptr) 3. Development workflow diff --git a/src/lib/du_buff.c b/src/lib/du_buff.c index 324dccc5..ea6206f9 100644 --- a/src/lib/du_buff.c +++ b/src/lib/du_buff.c @@ -84,7 +84,7 @@ struct buffer * buffer_create (size_t size, size_t headspace, size_t len) size_t ts = size - (headspace + len); bool head_block = true; - head = (struct buffer *) malloc(sizeof(struct buffer)); + head = malloc(sizeof *head); head->size=0; head->data=NULL; @@ -108,14 +108,14 @@ struct buffer * buffer_create (size_t size, size_t headspace, size_t len) sz = remaining < page_size ? remaining : page_size; } - buf = (struct buffer *) malloc(sizeof(struct buffer)); + buf = malloc(sizeof *buf); if (buf == NULL) { LOG_WARN("Could not allocate struct."); return NULL; } if (sz > 0) { - buf->data = (uint8_t *) malloc(sz); + buf->data = malloc(sz); if (buf->data == NULL) { LOG_WARN("Could not allocate memory block."); buffer_destroy_list(head); -- cgit v1.2.3 From 5ed07e6935a73bd54dd31c96afdf478a42d70ea1 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Fri, 26 Feb 2016 15:02:23 +0100 Subject: doc: workflow updated for consistency --- doc/workflow.txt | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/doc/workflow.txt b/doc/workflow.txt index 02d13f64..0f59b4bf 100644 --- a/doc/workflow.txt +++ b/doc/workflow.txt @@ -23,18 +23,14 @@ int *a; - Don't explicitly cast malloc, but do -your * = malloc (sizeof *your * len); - -or - your * = malloc (sizeof (*your) * len); +or +your * = malloc (sizeof *your * len); - When checking for invalid pointers use if (ptr == NULL) - instead of - if (!ptr) 3. Development workflow -- cgit v1.2.3 From 223813bbd609d929537b9f3f54bf4eec99d7663b Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Fri, 26 Feb 2016 22:49:25 +0100 Subject: doc: fixed example code in workflow doc --- doc/workflow.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/workflow.txt b/doc/workflow.txt index 0f59b4bf..a829192b 100644 --- a/doc/workflow.txt +++ b/doc/workflow.txt @@ -23,9 +23,9 @@ int *a; - Don't explicitly cast malloc, but do -your * = malloc (sizeof (*your) * len); +ptr = malloc (sizeof(*ptr) * len); or -your * = malloc (sizeof *your * len); +ptr = malloc (sizeof *ptr * len); - When checking for invalid pointers use -- cgit v1.2.3