This is the mail archive of the ecos-patches@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: eCos uSTL 1.3 port for review


Sergei Gavrikov wrote:
Uwe

Today when I do re-test all from scratch (ustl build on synthetic), I
found that this patch does not work. It seems that I ran in false clean
up.  The previous tweak:

virtual ~Cyg_VsnprintfStream() { /* *s_ = '\0'; */ }

works only. I cannot know why this assignment

*s_ = '\0';

there :-(

So, such the desctuctor (the below) works for synthetic ustl build

virtual ~Cyg_VsnprintfStream() {}

I'm sorry about. It seems we should ask Jonathan Larmour about this
terminator.

I don't believe vfnprintf() adds trailing null terminators in its output, but the string needs one, so this is how it's added. Otherwise you are gambling on the memory pointed to by the string already having NULLs in. I suspect when you've had this working, that has happened to be the case.


I think I know what the real problem is - if the string is truncated, the NULL will be placed after the "size" argument. Please try the attached untested patch (not yet committed).

Jifl

On Thu, Aug 06, 2009 at 04:56:03PM +0300, Sergei Gavrikov wrote:

On Thu, Aug 06, 2009 at 04:25:11PM +0300, Sergei Gavrikov wrote:

On Thu, Aug 06, 2009 at 03:44:16PM +0300, Sergei Gavrikov wrote:

Uwe Kindler wrote:

It would be really great, If you could investigate a little bit more, what causes the SIGSEG for synthetic target. Would you be so kind to run the new snprintf_c99.c test on synthetic target when C99 compliance activated to check if my vfnprintf() patch is working properly?


Uwe,

snprintf_c99 test passed successfully on synth. It seems that I should
grep all  #if linux in ustl and look on that. I will try to rebuild ustl
with assertions and will try to re-run the tests. I'll let you know what
I will get then.

Hm, Uwe, SIGSEG occured on a call of a destructor in vsnprintf.cxx (it's not your source). The uSTL test run on synthetic target with this dirty tweak. Do you have any thoughts?


With this patch both set of tests libc/stdio and cxx/ustl passed
successfully on synthetic target.

Sergei


Index: vsnprintf.cxx
===================================================================
RCS file: /cvs/ecos/ecos/packages/language/c/libc/stdio/current/src/common/vsnprintf.cxx,v
retrieving revision 1.6
diff -u -r1.6 vsnprintf.cxx
--- vsnprintf.cxx	29 Jan 2009 17:49:53 -0000	1.6
+++ vsnprintf.cxx	6 Aug 2009 13:49:24 -0000
@@ -71,7 +71,7 @@
public:
    Cyg_VsnprintfStream(char* s): s_(s) {}

-    virtual ~Cyg_VsnprintfStream() { *s_ = '\0'; }
+    virtual ~Cyg_VsnprintfStream() { if (s_) *s_ = '\0'; }

    virtual Cyg_ErrNo write( const cyg_uint8 *buffer,
        cyg_ucount32 buffer_length, cyg_ucount32 *bytes_written );






--
eCosCentric Limited      http://www.eCosCentric.com/     The eCos experts
Barnwell House, Barnwell Drive, Cambridge, UK.       Tel: +44 1223 245571
Registered in England and Wales: Reg No 4422071.
------["The best things in life aren't things."]------      Opinions==mine
Index: ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/language/c/libc/stdio/current/ChangeLog,v
retrieving revision 1.47
diff -u -5 -p -r1.47 ChangeLog
--- ChangeLog	16 Feb 2009 21:41:12 -0000	1.47
+++ ChangeLog	7 Aug 2009 13:40:26 -0000
@@ -1,5 +1,11 @@
+2009-08-07  Jonathan Larmour  <jifl@eCosCentric.com>
+
+	* src/common/vsnprintf.cxx (class Cyg_VsnprintfStream):
+	Remove destructor.
+	(vsnprintf): Apply null terminator correctly when truncated.
+
 2009-02-16  Lars Povlsen  <lpovlsen@vitesse.com>
 
 	* include/stdio.h: Removed extra semicolon after scanf()
 	prototype.
 
Index: src/common/vsnprintf.cxx
===================================================================
RCS file: /cvs/ecos/ecos/packages/language/c/libc/stdio/current/src/common/vsnprintf.cxx,v
retrieving revision 1.6
diff -u -5 -p -r1.6 vsnprintf.cxx
--- src/common/vsnprintf.cxx	29 Jan 2009 17:49:53 -0000	1.6
+++ src/common/vsnprintf.cxx	7 Aug 2009 13:40:26 -0000
@@ -69,12 +69,10 @@
 class Cyg_VsnprintfStream: public Cyg_OutputStream
 {
 public:
     Cyg_VsnprintfStream(char* s): s_(s) {}
 
-    virtual ~Cyg_VsnprintfStream() { *s_ = '\0'; }
-
     virtual Cyg_ErrNo write( const cyg_uint8 *buffer,
         cyg_ucount32 buffer_length, cyg_ucount32 *bytes_written );
 
     virtual Cyg_ErrNo get_error( void ) { return ENOERR; }
 
@@ -99,10 +97,17 @@ Cyg_VsnprintfStream::write(
 }
 
 externC int
 vsnprintf( char *s, size_t size, const char *format, va_list arg ) __THROW
 {
+    int ret;
     Cyg_VsnprintfStream stream(s);
-    return vfnprintf( (FILE *)(void *)&stream, size, format, arg );
+    ret = vfnprintf( (FILE *)(void *)&stream, size, format, arg );
+    /* If no error, and string not truncated, then apply null termination in
+     * correct place
+     */
+    if ( (ret >= 0) && (ret < size) )
+        s[ret] = '\0';
+    return ret;
 } // vsnprintf()
 
 // EOF vsnprintf.cxx

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]