Austin Group Defect Tracker

Aardvark Mark III


Viewing Issue Simple Details Jump to Notes ] Issue History ] Print ]
ID Category Severity Type Date Submitted Last Update
0001153 [1003.1(2008)/Issue 7] System Interfaces Editorial Clarification Requested 2017-06-22 08:02 2017-06-22 08:02
Reporter Villemoes View Status public  
Assigned To ajosey
Priority normal Resolution Open  
Status Under Review  
Name Rasmus Villemoes
Organization
User Reference
Section fmemopen
Page Number
Line Number
Interp Status ---
Final Accepted Text
Summary 0001153: 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.

#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;
}

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.
Tags No tags attached.
Attached Files

- Relationships

There are no notes attached to this issue.

- 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


Mantis 1.1.6[^]
Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker