This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc 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]

[Bug libc/1995] fprintf() + fmemopen() error (?)


------- Additional Comments From rsa at us dot ibm dot com  2006-03-31 18:56 -------
I checked through the C99 spec and "The Open Group Base Specifications Issue 6
IEEE Std 1003.1, 2004 Edition" and couldn't find any expressed behavior
regarding the return value of fprintf when only partial data is written.

investigation:

In this case fmemopen() sets the fp stream's internal write function to:
iof.write = fmemopen_write;

In libio/fmemopen.c
fmemopen_write() only writes 's' number of characters where 's' is the number of
characters that can fit in the remaining buffer space:

s = c->size - c->pos - addnullc;

In stdio-common/vfprintf.c we see that PUT should call on the 's' (fp) stream's
fopenmem_write function:

#define outstring(String, Len)                                                \
  do                                                                          \
    {                                                                         \
      if ((size_t) PUT (s, (String), (Len)) != (size_t) (Len))                \
        {                                                                     \
          done = -1;                                                          \
          goto all_done;                                                      \
        }                                                                     \
      done += (Len);                                                          \
    }                                                                         \
  while (0)

In the case where 'Len' exceeds the space in the buffer 'done' will be set to -1.

Since fopenmem_write() doesn't return 'Len', but only the amount of data written
to the buffer there seems to be a problem if '-1' isn't being returned for this
test case.

I intend to check whether fopenmem_write() really is being invoked when
'outstring' is called.



-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=1995

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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