The following issue has been SUBMITTED. 
====================================================================== 
http://austingroupbugs.net/view.php?id=1153 
====================================================================== 
Reported By:                Villemoes
Assigned To:                ajosey
====================================================================== 
Project:                    1003.1(2008)/Issue 7
Issue ID:                   1153
Category:                   System Interfaces
Type:                       Clarification Requested
Severity:                   Editorial
Priority:                   normal
Status:                     Under Review
Name:                       Rasmus Villemoes 
Organization:                
User Reference:              
Section:                    fmemopen 
Page Number:                 
Line Number:                 
Interp Status:              --- 
Final Accepted Text:         
====================================================================== 
Date Submitted:             2017-06-22 08:02 UTC
Last Modified:              2017-06-22 08:02 UTC
====================================================================== 
Summary:                    fread/fwrite to/from buffer underlying the memory
stream
Description: 
In glibc, running the code below under valgrind gives a

  Source and destination overlap in memcpy

Without the setvbuf calls, this doesn't trigger because the reads and
writes happen via an internal buffer.

I cannot find anything that says the application cannot do fread/fwrite
calls on a memory stream, using part of the stream's underlying buffer as
destination/source.

<pre>
#include <stdio.h>

int main(int argc, char *argv[])
{
        char x[4] = "123";
        char y[4] = "abc";
        FILE *f = fmemopen(x, 3, "r");
        FILE *g = fmemopen(y, 3, "w");
        setvbuf(f, NULL, _IONBF, 0);
        setvbuf(g, NULL, _IONBF, 0);

        fread(&x[1], 1, 2, f);
        fwrite(&y[1], 1, 2, g);
        
        printf("x = %s\n", x);
        printf("y = %s\n", y);
        
        fclose(f);
        fclose(g);

        printf("x = %s\n", x);
        printf("y = %s\n", y);
        
        return 0;
}
</pre>

Desired Action: 
Clarify whether the implementation must behave as if it was using memmove
internally, or alternatively, that it is up to the application to avoid
fread/fwrite calls on memory streams that will trigger such copies. The
latter seems hard to do in general.
====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2017-06-22 08:02 Villemoes      New Issue                                    
2017-06-22 08:02 Villemoes      Status                   New => Under Review 
2017-06-22 08:02 Villemoes      Assigned To               => ajosey          
2017-06-22 08:02 Villemoes      Name                      => Rasmus Villemoes
2017-06-22 08:02 Villemoes      Section                   => fmemopen        
======================================================================


Reply via email to