Email List: Xaustin-review-lX
[All Lists]

Defect in API Set 1: XSH fmemopen

To: <yyyyyyyyyyyyyyy@xxxxxxxxxxxxx>
Subject: Defect in API Set 1: XSH fmemopen
From: "Alexey V. Khoroshilov" <yyyyyyyyyyy@xxxxxxxxx>
Date: Thu, 16 Feb 2006 10:49:00 +0300
Organization: ISP RAS
Problem: API Set 1(Draft January 12, 2006)
There are three defects detected in the description of the fmemopen() function.
1.
The description reads:
 
    321 If a null pointer is specified as the buf argument, fmemopen( ) shall allocate size bytes of memory
    322 as if by a call to malloc( ). This buffer shall be automatically freed when the stream is closed.
    323 Because this feature is only useful when the stream is opened for updating (because there is no
    324 way to get a pointer to the buffer) the fmemopen( ) call may fail if the mode argument does not
    325 include a ’+’.
    326 The stream maintains a current position in the buffer. This position is initially set to either the
    327 begining of the buffer (for r and w modes) or to the first null byte in the buffer (for a modes). If
    328 no null byte is found in append mode, the initial position is set to one byte after the end of the
    329 buffer.
 
It follows if a null pointer is specified as the buf argument and mode had 'a' as the first character,
the initial value of the current position is a random value.
Memory allocated by a call to malloc( ) contains accidental bytes. So the first null byte in the buffer is
at a random position.
 
Proposed action:
Add explicit definition of the initial value of the current position in this situation.
The begining of the buffer is the best choice in my view.
 
 
2.
The misprint is in the sentence at lines 336-337: 'The write operation starts at the current buffer position of the stream.'
I guess it shall read: 'The read operation starts at the current buffer position of the stream.'
 
    334 A read operation on the stream cannot advance the current buffer position behind the current
    335 buffer size. Reaching the buffer size in a read operation counts as "end of file". Null bytes in the
    336 buffer have no special meaning for reads. The write operation starts at the current buffer
    337 position of the stream.
    338 A write operation starts either at the current position of the stream (if mode has not specified a
    339 as the first character) or at the current size of the stream (if mode had a as the first character). If
    340 the current position at the end of the write is larger than the current buffer size, the current
    341 buffer size is set to the current position. A write operation on the stream cannot advance the
    342 current buffer size behind the size given in the size argument.
 
 
Proposed action:
 
Replace
 
    334 A read operation on the stream cannot advance the current buffer position behind the current
    335 buffer size. Reaching the buffer size in a read operation counts as "end of file". Null bytes in the
    336 buffer have no special meaning for reads. The write operation starts at the current buffer
    337 position of the stream.
by
 
    334 A read operation on the stream cannot advance the current buffer position behind the current
    335 buffer size. Reaching the buffer size in a read operation counts as "end of file". Null bytes in the
    336 buffer have no special meaning for reads. The read operation starts at the current buffer
    337 position of the stream.
 
3.
The description
 
    343 When a stream open for writing is flushed or closed, a null byte is written at the end of the buffer
    344 if it fits. If a stream open for update is flushed or closed and the last write has advanced the
    345 current buffer size, a null byte is written at the end of the buffer if it fits.
    346 An attempt to seek a memory buffer stream to a negative position or to a position larger than the
    347 buffer size given in the size argument shall fail.
is unclear.
'the end of the buffer' can be understood in two ways: either the size of the current contents
or the size of the buffer itself.
'if it fits' in this context is also unclear.
 
 
Alexey V. Khoroshilov,
UniTesK Lab, ISP RAS.
e-mail:
khoroshilov@xxxxxx
 
 
P.S.
I guess the bug report shall be posted by means of a bug report form, but the link http://www.opengroup.org/austin/bugreport.html does not work.
 
<Prev in Thread] Current Thread [Next in Thread>