octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

MSVC compiler support [patch 28]: setvbuf crash


From: John W. Eaton
Subject: MSVC compiler support [patch 28]: setvbuf crash
Date: Wed, 25 Oct 2006 21:18:22 -0400

On 17-Oct-2006, Michael Goffioul wrote:

| setvbuf leads to a crash when called on a pipe (don't know why).
| 
| Index: src/oct-procbuf.cc
| ===================================================================
| RCS file: /cvs/octave/src/oct-procbuf.cc,v
| retrieving revision 1.30
| diff -p -c -r1.30 oct-procbuf.cc
| *** src/oct-procbuf.cc        8 May 2006 20:23:05 -0000       1.30
| --- src/oct-procbuf.cc        17 Oct 2006 11:07:42 -0000
| *************** octave_procbuf::open (const char *comman
| *** 78,85 ****
| --- 78,87 ----
|   
|     open_p = true;
|   
| + #ifndef _MSC_VER
|     if (mode & std::ios::out)
|       ::setvbuf (f, 0, _IOLBF, 0);
| + #endif
|   
|     return this;

Perhaps this is crashing because size (the final argument) is 0.  Can
you try using something like 1024 and see if that works?  My
understanding was that if the buffer pointer was 0, the buffer would
be automatically allocated, and at some point I must have thought that
the buffer would also be appropriately sized if the SIZE argument is
0.  But the MSDN man page says

  The array pointed to by buffer is used as the buffer, unless it is
  NULL, in which case setvbuf uses an automatically allocated buffer
  of length size/2 * 2 bytes.

so I guess we need to set size to a nonzero value.  I think POSIX
specifies BUFSIZE as an approprite size, so I changed this code to use

  :setvbuf (f, 0, _IOLBF, BUFSIZ);

and I'm defining BUFSIZ at the top of the file this way:

  #ifndef BUFSIZ
  #define BUFSIZ 1024
  #endif

Thanks,

jwe



reply via email to

[Prev in Thread] Current Thread [Next in Thread]