summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/workflow.txt12
-rw-r--r--src/lib/du_buff.c6
2 files changed, 15 insertions, 3 deletions
diff --git a/doc/workflow.txt b/doc/workflow.txt
index ee4afb95..a829192b 100644
--- a/doc/workflow.txt
+++ b/doc/workflow.txt
@@ -21,6 +21,18 @@ int * a;
instead of
int *a;
+- Don't explicitly cast malloc, but do
+
+ptr = malloc (sizeof(*ptr) * len);
+or
+ptr = malloc (sizeof *ptr * 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
diff --git a/src/lib/du_buff.c b/src/lib/du_buff.c
index f365ffc2..bfb33339 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);