libc/stdlib/nano-mallocr.c, typo in variable name

Message ID 1515662fc3254a75c831e4f0c02049b8@sourceware.mail.kapsi.fi
State New
Headers
Series libc/stdlib/nano-mallocr.c, typo in variable name |

Commit Message

Pekka Seppänen Aug. 28, 2023, 11:02 a.m. UTC
  Hi,

Nano malloc uses `size' in assertation whereas the correct variable 
would be `s'.  Given this has existed ever since nano malloc support was 
added, based on the context ("returned payload area of desired size does 
not exceed the actual allocated chunk") I presume that indeed `s' (user 
input) and not `r->size' (computed) shall be used.

---
  

Comments

Corinna Vinschen Aug. 29, 2023, 12:36 p.m. UTC | #1
On Aug 28 14:02, Pekka Seppänen wrote:
> Hi,
> 
> Nano malloc uses `size' in assertation whereas the correct variable would be
> `s'.  Given this has existed ever since nano malloc support was added, based
> on the context ("returned payload area of desired size does not exceed the
> actual allocated chunk") I presume that indeed `s' (user input) and not
> `r->size' (computed) shall be used.
> 
> ---
> 
> diff --git a/newlib/libc/stdlib/nano-mallocr.c
> b/newlib/libc/stdlib/nano-mallocr.c
> index a2b50facc..41e69abb0 100644
> --- a/newlib/libc/stdlib/nano-mallocr.c
> +++ b/newlib/libc/stdlib/nano-mallocr.c
> @@ -396,7 +396,7 @@ void * nano_malloc(RARG malloc_size_t s)
>          *(long *)((char *)r + offset) = -offset;
>      }
> 
> -    assert(align_ptr + size <= (char *)r + alloc_size);
> +    assert(align_ptr + s <= (char *)r + alloc_size);
>      return align_ptr;
>  }
>  #endif /* DEFINE_MALLOC */

Given that r->size == alloc_size, checking for r->size would lead
to the assertion always failing if align_ptr != ptr.

So, yeah, s seems indeed the right choice.  Pushed.


Thanks,
Corinna
  

Patch

diff --git a/newlib/libc/stdlib/nano-mallocr.c 
b/newlib/libc/stdlib/nano-mallocr.c
index a2b50facc..41e69abb0 100644
--- a/newlib/libc/stdlib/nano-mallocr.c
+++ b/newlib/libc/stdlib/nano-mallocr.c
@@ -396,7 +396,7 @@  void * nano_malloc(RARG malloc_size_t s)
          *(long *)((char *)r + offset) = -offset;
      }

-    assert(align_ptr + size <= (char *)r + alloc_size);
+    assert(align_ptr + s <= (char *)r + alloc_size);
      return align_ptr;
  }
  #endif /* DEFINE_MALLOC */