Re: [PATCH] MSP430: Fix message in sbrk.c printing binary character

Jozef Lawrynowicz <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <20200903130223.yq62ydnjp4ajpci5@jozef-acer-manjaro>
On Thu, Sep 03, 2020 at 12:14:45PM +0000, Łukasz Żak wrote:
> I would like to point out that this patch is in fact incorrect. 
> 
> >+      const char * const msg = "Heap and stack collision\n";
> >+      write (1, msg, sizeof (msg) - 1);
> 
> As msg is pointer then sizeof(msg) will be the size of pointer and not the length of the actual string literal, 
> therefore the write call will capture only the beginning of the message.

Whoops, my mistake, thanks for spotting that.
Fixed in the attached patch.

Thanks,
Jozef

> 
> Regards,
> Łukasz Żak
>
0001-MSP430-Fix-calculation-of-string-length-in-sbrk.c.patch (text/plain, 726 B)
From 32a56f154205b179512cfab2a7523fb855898a8a Mon Sep 17 00:00:00 2001
From: Jozef Lawrynowicz <[email protected]>
Date: Thu, 3 Sep 2020 14:00:32 +0100
Subject: [PATCH] MSP430: Fix calculation of string length in sbrk.c

---
 libgloss/msp430/sbrk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libgloss/msp430/sbrk.c b/libgloss/msp430/sbrk.c
index 8e4339f6e..01d13b792 100644
--- a/libgloss/msp430/sbrk.c
+++ b/libgloss/msp430/sbrk.c
@@ -24,7 +24,7 @@ _sbrk (int adj)
 
   if (heap + adj > sp)
     {
-      const char * const msg = "Heap and stack collision\n";
+      const char msg[] = "Heap and stack collision\n";
       write (1, msg, sizeof (msg) - 1);
       abort ();
     }
-- 
2.28.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.