A NOTE has been added to this issue. ====================================================================== http://austingroupbugs.net/view.php?id=1144 ====================================================================== Reported By: Villemoes Assigned To: ajosey ====================================================================== Project: 1003.1(2008)/Issue 7 Issue ID: 1144 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-14 14:31 UTC Last Modified: 2017-06-14 19:35 UTC ====================================================================== Summary: May fmemopen(buf, len, "r") modify the buffer ======================================================================
---------------------------------------------------------------------- (0003762) Villemoes (reporter) - 2017-06-14 19:35 http://austingroupbugs.net/view.php?id=1144#c3762 ---------------------------------------------------------------------- Maybe I wasn't clear, but I'm not concerned about what might happen if the application calls fwrite() or similar on the handle. What concerns me is that nothing seems to prevent the implementation from doing something crazy like this in implementing a read-only memstream: fmemopen: f->orig = buf; f->buf = malloc(len); f->len = len; memcpy(f->buf, buf, len); memset(buf, 0, len); fclose: memcpy(f->orig, f->buf, f->len); The last sentence was about what one can expect from code such as char a[3] = "xxx", b[3]; f = fmemopen(a, 3, "r"); fread(&b[0], 1, 1, f); a[1] = 'y'; fread(&b[1], 1, 1, f); Is b[1] now 'x' or 'y'? Or is the access to a forbidden while f is "bound" to the buffer? Come to think of it: Obvious implementations of memstreams use memcpy to implement fread and fwrite, but is a call such as fread(&a[1], 1, 2, f) (with f just opened as above) allowed? Must the implementation support this and use memmove, or is it up to the application to avoid such calls? But you also raise some valid points about the lifetime of the buffer; there should probably be some wording added about the application having to ensure that the buffer isn't deallocated before fclose(). Issue History Date Modified Username Field Change ====================================================================== 2017-06-14 14:31 Villemoes New Issue 2017-06-14 14:31 Villemoes Status New => Under Review 2017-06-14 14:31 Villemoes Assigned To => ajosey 2017-06-14 14:31 Villemoes Name => Rasmus Villemoes 2017-06-14 14:31 Villemoes Section => fmemopen 2017-06-14 16:41 shware_systems Note Added: 0003761 2017-06-14 19:35 Villemoes Note Added: 0003762 ======================================================================