This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


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

[PATCH] Fix putwchar


Hi!

This patch fixes col segfault. It can be reproduced by:
#include <wchar.h>

int main(void)
{
  int i;
  for (i = 0; i < 4098; i++)
    putwchar(i & 255);
}
and running a.out > out
(ie. stderr redirected into file).
size used to be computed in bytes, but then used in wchar_t pointer
arithmetics. This patch changes it size to be in characters and only do the
shift left in ALLOC_WBUF argument. Alternatively, p + size could be replaced
with p + (size / sizeof(wchar_t)) but that means more shifting all around.

2000-07-24  Jakub Jelinek  <jakub@redhat.com>

	* libio/wfiledoalloc.c (_IO_wfile_doallocate): Measure size
	in wide characters, not bytes.

--- libc/libio/wfiledoalloc.c.jj	Tue Jan  4 11:11:50 2000
+++ libc/libio/wfiledoalloc.c	Mon Jul 24 22:16:53 2000
@@ -1,4 +1,4 @@
-/* Copyright (C) 1993, 1997, 1999 Free Software Foundation, Inc.
+/* Copyright (C) 1993, 1997, 1999, 2000 Free Software Foundation, Inc.
    This file is part of the GNU IO Library.
 
    This library is free software; you can redistribute it and/or
@@ -81,7 +81,7 @@ _IO_wfile_doallocate (fp)
   if (fp->_fileno < 0 || _IO_SYSSTAT (fp, &st) < 0)
     {
       couldbetty = 0;
-      size = _IO_BUFSIZ * sizeof (wchar_t);
+      size = _IO_BUFSIZ;
 #if 0
       /* do not try to optimise fseek() */
       fp->_flags |= __SNPT;
@@ -91,13 +91,12 @@ _IO_wfile_doallocate (fp)
     {
       couldbetty = S_ISCHR (st.st_mode);
 #if _IO_HAVE_ST_BLKSIZE
-      size = ((st.st_blksize <= 0 ? _IO_BUFSIZ : st.st_blksize)
-	      * sizeof (wchar_t));
+      size = st.st_blksize <= 0 ? _IO_BUFSIZ : st.st_blksize;
 #else
-      size = _IO_BUFSIZ * sizeof (wchar_t);
+      size = _IO_BUFSIZ;
 #endif
     }
-  ALLOC_WBUF (p, size, EOF);
+  ALLOC_WBUF (p, size * sizeof (wchar_t), EOF);
   _IO_wsetb (fp, p, p + size, 1);
   if (couldbetty && isatty (fp->_fileno))
     fp->_flags |= _IO_LINE_BUF;

	Jakub

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