Mail Archives: djgpp-workers/2005/05/03/16:23:36
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 -