Just like in the new ifstream, if we are out of memory it's better to fail loudly with an obvious FIXME message than to leave user with half-initialized object causing ephemeral issues that are hard to debug.
Signed-off-by: Arkadiusz Hiler ahiler@codeweavers.com ---
v2: style consistency - inline curly brackets with if statements
dlls/msvcirt/msvcirt.c | 81 ++++++++++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 31 deletions(-)
diff --git a/dlls/msvcirt/msvcirt.c b/dlls/msvcirt/msvcirt.c index 7e1d9977b78..959322bdc86 100644 --- a/dlls/msvcirt/msvcirt.c +++ b/dlls/msvcirt/msvcirt.c @@ -3012,11 +3012,15 @@ ostream* __thiscall ostrstream_buffer_ctor(ostream *this, char *buffer, int leng
TRACE("(%p %p %d %d %d)\n", this, buffer, length, mode, virt_init);
- if (ssb) { - strstreambuf_buffer_ctor(ssb, buffer, length, buffer); - if (mode & (OPENMODE_app|OPENMODE_ate)) - ssb->base.pptr = buffer + strlen(buffer); + if (!ssb) { + FIXME("out of memory\n"); + return NULL; } + + strstreambuf_buffer_ctor(ssb, buffer, length, buffer); + if (mode & (OPENMODE_app|OPENMODE_ate)) + ssb->base.pptr = buffer + strlen(buffer); + return ostrstream_internal_sb_ctor(this, ssb, virt_init); }
@@ -3029,8 +3033,13 @@ ostream* __thiscall ostrstream_ctor(ostream *this, BOOL virt_init)
TRACE("(%p %d)\n", this, virt_init);
- if (ssb) - strstreambuf_ctor(ssb); + if (!ssb) { + FIXME("out of memory\n"); + return NULL; + } + + strstreambuf_ctor(ssb); + return ostrstream_internal_sb_ctor(this, ssb, virt_init); }
@@ -4069,11 +4078,14 @@ istream* __thiscall istrstream_buffer_ctor(istream *this, char *buffer, int leng
TRACE("(%p %p %d %d)\n", this, buffer, length, virt_init);
- if (ssb) { - strstreambuf_buffer_ctor(ssb, buffer, length, NULL); - istream_sb_ctor(this, &ssb->base, virt_init); - } else - istream_ctor(this, virt_init); + if (!ssb) { + FIXME("out of memory\n"); + return NULL; + } + + strstreambuf_buffer_ctor(ssb, buffer, length, NULL); + istream_sb_ctor(this, &ssb->base, virt_init); + base = istream_get_ios(this); base->vtable = &MSVCP_istrstream_vtable; base->delbuf = 1; @@ -4125,8 +4137,7 @@ istream* __thiscall ifstream_buffer_ctor(istream *this, filedesc fd, char *buffe
TRACE("(%p %d %p %d %d)\n", this, fd, buffer, length, virt_init);
- if (!fb) - { + if (!fb) { FIXME("out of memory\n"); return NULL; } @@ -4151,8 +4162,7 @@ istream* __thiscall ifstream_fd_ctor(istream *this, filedesc fd, BOOL virt_init)
TRACE("(%p %d %d)\n", this, fd, virt_init);
- if (!fb) - { + if (!fb) { FIXME("out of memory\n"); return NULL; } @@ -4177,8 +4187,7 @@ istream* __thiscall ifstream_open_ctor(istream *this, const char *name, ios_open
TRACE("(%p %s %d %d %d)\n", this, name, mode, protection, virt_init);
- if (!fb) - { + if (!fb) { FIXME("out of memory\n"); return NULL; } @@ -4470,13 +4479,17 @@ iostream* __thiscall strstream_buffer_ctor(iostream *this, char *buffer, int len
TRACE("(%p %p %d %d %d)\n", this, buffer, length, mode, virt_init);
- if (ssb) { - strstreambuf_buffer_ctor(ssb, buffer, length, buffer); - if ((mode & OPENMODE_out) && (mode & (OPENMODE_app|OPENMODE_ate))) - ssb->base.pptr = buffer + strlen(buffer); - return iostream_internal_sb_ctor(this, &ssb->base, &MSVCP_strstream_vtable, virt_init); + if (!ssb) { + FIXME("out of memory\n"); + return NULL; } - return iostream_internal_sb_ctor(this, NULL, &MSVCP_strstream_vtable, virt_init); + + strstreambuf_buffer_ctor(ssb, buffer, length, buffer); + + if ((mode & OPENMODE_out) && (mode & (OPENMODE_app|OPENMODE_ate))) + ssb->base.pptr = buffer + strlen(buffer); + + return iostream_internal_sb_ctor(this, &ssb->base, &MSVCP_strstream_vtable, virt_init); }
/* ??0strstream@@QAE@XZ */ @@ -4488,11 +4501,14 @@ iostream* __thiscall strstream_ctor(iostream *this, BOOL virt_init)
TRACE("(%p %d)\n", this, virt_init);
- if (ssb) { - strstreambuf_ctor(ssb); - return iostream_internal_sb_ctor(this, &ssb->base, &MSVCP_strstream_vtable, virt_init); + if (!ssb) { + FIXME("out of memory\n"); + return NULL; } - return iostream_internal_sb_ctor(this, NULL, &MSVCP_strstream_vtable, virt_init); + + strstreambuf_ctor(ssb); + + return iostream_internal_sb_ctor(this, &ssb->base, &MSVCP_strstream_vtable, virt_init); }
/* ?pcount@strstream@@QBEHXZ */ @@ -4537,11 +4553,14 @@ iostream* __thiscall stdiostream_file_ctor(iostream *this, FILE *file, BOOL virt
TRACE("(%p %p %d)\n", this, file, virt_init);
- if (stb) { - stdiobuf_file_ctor(stb, file); - return iostream_internal_sb_ctor(this, &stb->base, &MSVCP_stdiostream_vtable, virt_init); + if (!stb) { + FIXME("out of memory\n"); + return NULL; } - return iostream_internal_sb_ctor(this, NULL, &MSVCP_stdiostream_vtable, virt_init); + + stdiobuf_file_ctor(stb, file); + + return iostream_internal_sb_ctor(this, &stb->base, &MSVCP_stdiostream_vtable, virt_init); }
/* ?rdbuf@stdiostream@@QBEPAVstdiobuf@@XZ */
September 4, 2020 4:44 AM, "Arkadiusz Hiler" ahiler@codeweavers.com wrote:
diff --git a/dlls/msvcirt/msvcirt.c b/dlls/msvcirt/msvcirt.c index 7e1d9977b78..959322bdc86 100644 --- a/dlls/msvcirt/msvcirt.c +++ b/dlls/msvcirt/msvcirt.c @@ -3012,11 +3012,15 @@ ostream* __thiscall ostrstream_buffer_ctor(ostream *this, char *buffer, int leng
TRACE("(%p %p %d %d %d)\n", this, buffer, length, mode, virt_init);
- if (ssb) {
strstreambuf_buffer_ctor(ssb, buffer, length, buffer);
if (mode & (OPENMODE_app|OPENMODE_ate))
ssb->base.pptr = buffer + strlen(buffer);
- if (!ssb) {
FIXME("out of memory\n");
Shouldn't this be an ERR? It doesn't seem like this is the kind of problem we can fix. Ditto, the other instances of this you added.
Chip
Hi Chip,
See https://www.winehq.org/pipermail/wine-devel/2020-September/172895.html
Kind regards, Gijs
On Fri, Sep 4, 2020, 16:44 Chip Davis cdavis@codeweavers.com wrote:
September 4, 2020 4:44 AM, "Arkadiusz Hiler" ahiler@codeweavers.com wrote:
diff --git a/dlls/msvcirt/msvcirt.c b/dlls/msvcirt/msvcirt.c index 7e1d9977b78..959322bdc86 100644 --- a/dlls/msvcirt/msvcirt.c +++ b/dlls/msvcirt/msvcirt.c @@ -3012,11 +3012,15 @@ ostream* __thiscall
ostrstream_buffer_ctor(ostream *this, char *buffer, int leng
TRACE("(%p %p %d %d %d)\n", this, buffer, length, mode, virt_init);
- if (ssb) {
strstreambuf_buffer_ctor(ssb, buffer, length, buffer);
if (mode & (OPENMODE_app|OPENMODE_ate))
ssb->base.pptr = buffer + strlen(buffer);
- if (!ssb) {
FIXME("out of memory\n");
Shouldn't this be an ERR? It doesn't seem like this is the kind of problem we can fix. Ditto, the other instances of this you added.
Chip
Ah, OK. Thanks.
September 4, 2020 11:55 AM, "Gijs Vermeulen" <gijsvrm@gmail.com (mailto:gijsvrm@gmail.com?to=%22Gijs%20Vermeulen%22%20gijsvrm@gmail.com)> wrote: Hi Chip,See https://www.winehq.org/pipermail/wine-devel/2020-September/172895.html (https://www.winehq.org/pipermail/wine-devel/2020-September/172895.html)Kind regards,Gijs On Fri, Sep 4, 2020, 16:44 Chip Davis <cdavis@codeweavers.com (mailto:cdavis@codeweavers.com)> wrote: September 4, 2020 4:44 AM, "Arkadiusz Hiler" <ahiler@codeweavers.com (mailto:ahiler@codeweavers.com)> wrote:
diff --git a/dlls/msvcirt/msvcirt.c b/dlls/msvcirt/msvcirt.c index 7e1d9977b78..959322bdc86 100644 --- a/dlls/msvcirt/msvcirt.c +++ b/dlls/msvcirt/msvcirt.c @@ -3012,11 +3012,15 @@ ostream* __thiscall ostrstream_buffer_ctor(ostream *this, char *buffer, int leng
TRACE("(%p %p %d %d %d)n", this, buffer, length, mode, virt_init);
- if (ssb) {
- strstreambuf_buffer_ctor(ssb, buffer, length, buffer);
- if (mode & (OPENMODE_app|OPENMODE_ate))
- ssb->base.pptr = buffer + strlen(buffer);
- if (!ssb) {
- FIXME("out of memoryn");
Shouldn't this be an ERR? It doesn't seem like this is the kind of problem we can fix. Ditto, the other instances of this you added. Chip Chip