delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2005/05/03/16:23:36

X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f
From: <ams AT ludd DOT ltu DOT se>
Message-Id: <200505031026.j43AQ2W6005205@speedy.ludd.ltu.se>
Subject: Re: Bug 000366 (mbstowcs causes SIGSEGV when passed a NULL pointer)
In-Reply-To: <200505030858.j438wvU7006744@speedy.ludd.ltu.se>
"from ams AT ludd DOT ltu DOT se at May 3, 2005 10:58:57 am"
To: djgpp-workers AT delorie DOT com
Date: Tue, 3 May 2005 12:26:01 +0200 (CEST)
X-Mailer: ELM [version 2.4ME+ PL78 (25)]
MIME-Version: 1.0
X-ltu-MailScanner-Information: Please contact the ISP for more information
X-ltu-MailScanner: Found to be clean
X-MailScanner-From: ams AT ludd DOT ltu DOT se
Reply-To: djgpp-workers AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp-workers AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

According to ams AT ludd DOT ltu DOT se:
> Patch including test programs for this bug (pasted):

Uggh! And of course it's incorrect! Forget that one and look at this
one instead:
Index: djgpp/src/libc/ansi/locale/mbstowcs.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/locale/mbstowcs.c,v
retrieving revision 1.3
diff -p -u -r1.3 mbstowcs.c
--- djgpp/src/libc/ansi/locale/mbstowcs.c       17 Oct 2002 23:00:24 -0000      
1.3
+++ djgpp/src/libc/ansi/locale/mbstowcs.c       3 May 2005 20:19:47 -0000
@@ -1,3 +1,4 @@
+/* Copyright (C) 2005 DJ Delorie, see COPYING.DJ for details */
 /* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
 /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
 #include <stdlib.h>
@@ -6,8 +7,9 @@ size_t
 mbstowcs(wchar_t *wcs, const char *s, size_t n)
 {
   size_t i;
-  for (i=0; s[i] && (i+1<n); i++)
+  for (i=0; (i+1<n) && s[i]; i++)
     wcs[i] = s[i];
-  wcs[i] = 0;
+  if (i+1<n)
+    wcs[i] = 0;
   return i;
 }
Index: djgpp/src/libc/ansi/locale/wcstombs.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/locale/wcstombs.c,v
retrieving revision 1.3
diff -p -u -r1.3 wcstombs.c
--- djgpp/src/libc/ansi/locale/wcstombs.c       17 Oct 2002 23:00:24 -0000      
1.3
+++ djgpp/src/libc/ansi/locale/wcstombs.c       3 May 2005 20:19:47 -0000
@@ -1,3 +1,4 @@
+/* Copyright (C) 2005 DJ Delorie, see COPYING.DJ for details */
 /* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
 /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
 #include <stdlib.h>
@@ -6,8 +7,9 @@ size_t
 wcstombs(char *s, const wchar_t *wcs, size_t n)
 {
   size_t i;
-  for (i=0; wcs[i] && (i+1<n); i++)
+  for (i=0; (i+1<n) && wcs[i]; i++)
     s[i] = wcs[i];
-  s[i] = 0;
+  if (i+1<n)
+    s[i] = 0;
   return i;
 }
Index: djgpp/tests/libc/ansi/stdlib/makefile
===================================================================
RCS file: /cvs/djgpp/djgpp/tests/libc/ansi/stdlib/makefile,v
retrieving revision 1.3
diff -p -u -r1.3 makefile
--- djgpp/tests/libc/ansi/stdlib/makefile       8 Jun 2001 10:03:33 -0000       
1.3
+++ djgpp/tests/libc/ansi/stdlib/makefile       3 May 2005 18:51:08 -0000
@@ -2,10 +2,12 @@ TOP=../..
 
 SRC += env.c
 SRC += getenv.c
+SRC += mbstowcs.c
 SRC += shell.c
 SRC += strtod.c
 SRC += system.c
 SRC += system2.c
 SRC += tmalloc.c
+SRC += wcstombs.c
 
 include $(TOP)/../makefile.inc
Index: djgpp/tests/libc/ansi/stdlib/mbstowcs.c
===================================================================
RCS file: djgpp/tests/libc/ansi/stdlib/mbstowcs.c
diff -N djgpp/tests/libc/ansi/stdlib/mbstowcs.c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ djgpp/tests/libc/ansi/stdlib/mbstowcs.c     3 May 2005 18:51:08 -0000
@@ -0,0 +1,12 @@
+#include <stdlib.h>
+
+int main(void)
+{
+  size_t len;
+
+  char s[] = "A";
+
+  len = mbstowcs(NULL, s, 0);
+
+  return 0;
+}
Index: djgpp/tests/libc/ansi/stdlib/wcstombs.c
===================================================================
RCS file: djgpp/tests/libc/ansi/stdlib/wcstombs.c
diff -N djgpp/tests/libc/ansi/stdlib/wcstombs.c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ djgpp/tests/libc/ansi/stdlib/wcstombs.c     3 May 2005 18:51:08 -0000
@@ -0,0 +1,12 @@
+#include <stdlib.h>
+
+int main(void)
+{
+  size_t len;
+
+  wchar_t ws[] = L"A";
+
+  len = wcstombs(NULL, ws, 0);
+
+  return 0;
+}


Right,

						MartinS


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019