public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] MSP430: Fix message in sbrk.c printing binary character
@ 2020-09-03 10:23 Jozef Lawrynowicz
  2020-09-03 11:44 ` Corinna Vinschen
  0 siblings, 1 reply; 5+ messages in thread
From: Jozef Lawrynowicz @ 2020-09-03 10:23 UTC (permalink / raw)
  To: newlib

[-- Attachment #1: Type: text/plain, Size: 277 bytes --]

The call to write() in sbrk.c was using the wrong value for the length
argument, causing the NUL terminating character of the string to be
printed.

If the patch is acceptable, I would appreciate if someone would commit
it for me, as I do not have write access.

Thanks,
Jozef

[-- Attachment #2: 0001-MSP430-Fix-message-in-sbrk.c-printing-binary-charact.patch --]
[-- Type: text/plain, Size: 919 bytes --]

From 36c92acd1d6f4bbce4dccf837bbd249b838cd908 Mon Sep 17 00:00:00 2001
From: Jozef Lawrynowicz <jozef.l@mittosystems.com>
Date: Wed, 2 Sep 2020 16:16:55 +0100
Subject: [PATCH] MSP430: Fix message in sbrk.c printing binary character

The call to write() in sbrk.c was using the wrong value for the length
argument, causing the NUL terminating character of the string to be
printed.

---
 libgloss/msp430/sbrk.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libgloss/msp430/sbrk.c b/libgloss/msp430/sbrk.c
index bbc3fb5ba..8e4339f6e 100644
--- a/libgloss/msp430/sbrk.c
+++ b/libgloss/msp430/sbrk.c
@@ -24,8 +24,8 @@ _sbrk (int adj)
 
   if (heap + adj > sp)
     {
-#define MESSAGE "Heap and stack collision\n"
-      write (1, MESSAGE, sizeof MESSAGE);
+      const char * const msg = "Heap and stack collision\n";
+      write (1, msg, sizeof (msg) - 1);
       abort ();
     }
 
-- 
2.28.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] MSP430: Fix message in sbrk.c printing binary character
  2020-09-03 10:23 [PATCH] MSP430: Fix message in sbrk.c printing binary character Jozef Lawrynowicz
@ 2020-09-03 11:44 ` Corinna Vinschen
  2020-09-03 12:14   ` Łukasz Żak
  0 siblings, 1 reply; 5+ messages in thread
From: Corinna Vinschen @ 2020-09-03 11:44 UTC (permalink / raw)
  To: newlib

> >From 36c92acd1d6f4bbce4dccf837bbd249b838cd908 Mon Sep 17 00:00:00 2001
> From: Jozef Lawrynowicz <jozef.l@mittosystems.com>
> Date: Wed, 2 Sep 2020 16:16:55 +0100
> Subject: [PATCH] MSP430: Fix message in sbrk.c printing binary character
> 
> The call to write() in sbrk.c was using the wrong value for the length
> argument, causing the NUL terminating character of the string to be
> printed.
> 
> ---
>  libgloss/msp430/sbrk.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Pushed.


Thanks,
Corinna


^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH] MSP430: Fix message in sbrk.c printing binary character
  2020-09-03 11:44 ` Corinna Vinschen
@ 2020-09-03 12:14   ` Łukasz Żak
  2020-09-03 13:02     ` Jozef Lawrynowicz
  0 siblings, 1 reply; 5+ messages in thread
From: Łukasz Żak @ 2020-09-03 12:14 UTC (permalink / raw)
  To: newlib

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.

Regards,
Łukasz Żak

-----Original Message-----
From: Newlib <newlib-bounces@sourceware.org> On Behalf Of Corinna Vinschen via Newlib
Sent: Thursday, September 3, 2020 1:44 PM
To: newlib@sourceware.org
Cc: Corinna Vinschen <vinschen@redhat.com>
Subject: Re: [PATCH] MSP430: Fix message in sbrk.c printing binary character

> >From 36c92acd1d6f4bbce4dccf837bbd249b838cd908 Mon Sep 17 00:00:00 
> >2001
> From: Jozef Lawrynowicz <jozef.l@mittosystems.com>
> Date: Wed, 2 Sep 2020 16:16:55 +0100
> Subject: [PATCH] MSP430: Fix message in sbrk.c printing binary 
> character
> 
> The call to write() in sbrk.c was using the wrong value for the length 
> argument, causing the NUL terminating character of the string to be 
> printed.
> 
> ---
>  libgloss/msp430/sbrk.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Pushed.


Thanks,
Corinna


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] MSP430: Fix message in sbrk.c printing binary character
  2020-09-03 12:14   ` Łukasz Żak
@ 2020-09-03 13:02     ` Jozef Lawrynowicz
  2020-09-04 13:05       ` Corinna Vinschen
  0 siblings, 1 reply; 5+ messages in thread
From: Jozef Lawrynowicz @ 2020-09-03 13:02 UTC (permalink / raw)
  To: Łukasz Żak; +Cc: newlib

[-- Attachment #1: Type: text/plain, Size: 558 bytes --]

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
> 

[-- Attachment #2: 0001-MSP430-Fix-calculation-of-string-length-in-sbrk.c.patch --]
[-- Type: text/plain, Size: 726 bytes --]

From 32a56f154205b179512cfab2a7523fb855898a8a Mon Sep 17 00:00:00 2001
From: Jozef Lawrynowicz <jozef.l@mittosystems.com>
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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] MSP430: Fix message in sbrk.c printing binary character
  2020-09-03 13:02     ` Jozef Lawrynowicz
@ 2020-09-04 13:05       ` Corinna Vinschen
  0 siblings, 0 replies; 5+ messages in thread
From: Corinna Vinschen @ 2020-09-04 13:05 UTC (permalink / raw)
  To: newlib

On Sep  3 14:02, Jozef Lawrynowicz wrote:
> 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
> > 

> >From 32a56f154205b179512cfab2a7523fb855898a8a Mon Sep 17 00:00:00 2001
> From: Jozef Lawrynowicz <jozef.l@mittosystems.com>
> 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(-)

Pushed.


Thanks,
Corinna


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-09-04 13:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-03 10:23 [PATCH] MSP430: Fix message in sbrk.c printing binary character Jozef Lawrynowicz
2020-09-03 11:44 ` Corinna Vinschen
2020-09-03 12:14   ` Łukasz Żak
2020-09-03 13:02     ` Jozef Lawrynowicz
2020-09-04 13:05       ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).