diff options
| author | Giovanni Di Sirio <gdisirio@gmail.com> | 2015-03-06 19:25:26 +0000 | 
|---|---|---|
| committer | Giovanni Di Sirio <gdisirio@gmail.com> | 2015-03-06 19:25:26 +0000 | 
| commit | 8a410f6946ff9f4721b74781a91a56256b66a4df (patch) | |
| tree | 831e01f67745d982f762552f48cfbc2d9ed82de2 /os/rt/src/chheap.c | |
| parent | 07aba437fa499413e13b72441d6a76edf9ec8818 (diff) | |
| download | ChibiOS-8a410f6946ff9f4721b74781a91a56256b66a4df.tar.gz ChibiOS-8a410f6946ff9f4721b74781a91a56256b66a4df.tar.bz2 ChibiOS-8a410f6946ff9f4721b74781a91a56256b66a4df.zip | |
Even more MISRA.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7722 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/rt/src/chheap.c')
| -rw-r--r-- | os/rt/src/chheap.c | 20 | 
1 files changed, 12 insertions, 8 deletions
| diff --git a/os/rt/src/chheap.c b/os/rt/src/chheap.c index a2ed3ddb0..a2635c72d 100644 --- a/os/rt/src/chheap.c +++ b/os/rt/src/chheap.c @@ -106,12 +106,12 @@ void _heap_init(void) {   * @init
   */
  void chHeapObjectInit(memory_heap_t *heapp, void *buf, size_t size) {
 -  union heap_header *hp;
 +  union heap_header *hp = buf;
    chDbgCheck(MEM_IS_ALIGNED(buf) && MEM_IS_ALIGNED(size));
    heapp->h_provider = (memgetfunc_t)NULL;
 -  heapp->h_free.h.u.next = hp = buf;
 +  heapp->h_free.h.u.next = hp;
    heapp->h_free.h.size = 0;
    hp->h.u.next = NULL;
    hp->h.size = size - sizeof(union heap_header);
 @@ -141,8 +141,9 @@ void chHeapObjectInit(memory_heap_t *heapp, void *buf, size_t size) {  void *chHeapAlloc(memory_heap_t *heapp, size_t size) {
    union heap_header *qp, *hp, *fp;
 -  if (heapp == NULL)
 +  if (heapp == NULL) {
      heapp = &default_heap;
 +  }
    size = MEM_ALIGN_NEXT(size);
    qp = &heapp->h_free;
 @@ -151,7 +152,7 @@ void *chHeapAlloc(memory_heap_t *heapp, size_t size) {    while (qp->h.u.next != NULL) {
      hp = qp->h.u.next;
      if (hp->h.size >= size) {
 -      if (hp->h.size < size + sizeof(union heap_header)) {
 +      if (hp->h.size < (size + sizeof(union heap_header))) {
          /* Gets the whole block even if it is slightly bigger than the
             requested size because the fragment would be too small to be
             useful.*/
 @@ -176,7 +177,7 @@ void *chHeapAlloc(memory_heap_t *heapp, size_t size) {    /* More memory is required, tries to get it from the associated provider
       else fails.*/
 -  if (heapp->h_provider) {
 +  if (heapp->h_provider != NULL) {
      hp = heapp->h_provider(size + sizeof(union heap_header));
      if (hp != NULL) {
        hp->h.u.heap = heapp;
 @@ -266,10 +267,13 @@ size_t chHeapStatus(memory_heap_t *heapp, size_t *sizep) {    H_LOCK(heapp);
    sz = 0;
 -  for (n = 0, qp = &heapp->h_free; qp->h.u.next; n++, qp = qp->h.u.next) {
 -    sz += qp->h.u.next->h.size;
 +  n = 0;
 +  qp = &heapp->h_free;
 +  while (qp->h.u.next != NULL) {
 +    n++;
 +    qp = qp->h.u.next;
    }
 -  if (sizep) {
 +  if (sizep != NULL) {
      *sizep = sz;
    }
    H_UNLOCK(heapp);
 | 
