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(a)codeweavers.com>
---
dlls/msvcirt/msvcirt.c | 78 ++++++++++++++++++++++++++++--------------
1 file changed, 53 insertions(+), 25 deletions(-)
diff --git a/dlls/msvcirt/msvcirt.c b/dlls/msvcirt/msvcirt.c
index 7e1d9977b78..c8aaa146e54 100644
--- a/dlls/msvcirt/msvcirt.c
+++ b/dlls/msvcirt/msvcirt.c
@@ -3012,11 +3012,16 @@ 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 +3034,14 @@ 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 +4080,15 @@ 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;
@@ -4470,13 +4485,18 @@ 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 +4508,15 @@ 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 +4561,15 @@ 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 */
--
2.28.0