Skip to content
Snippets Groups Projects
Commit 9923f47c authored by Mark OLESEN's avatar Mark OLESEN
Browse files

ENH: remove size limit when reading verbatim strings (issue #785)

parent b7f3ca53
No related branches found
No related tags found
No related merge requests found
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
...@@ -471,8 +471,8 @@ Foam::Istream& Foam::ISstream::read(word& str) ...@@ -471,8 +471,8 @@ Foam::Istream& Foam::ISstream::read(word& str)
<< buf << nl << endl; << buf << nl << endl;
} }
// Finalize // Finalize: content already validated, assign without additional checks.
str = buf; str.assign(buf, nChar);
putback(c); putback(c);
return *this; return *this;
...@@ -568,7 +568,7 @@ Foam::Istream& Foam::ISstream::read(string& str) ...@@ -568,7 +568,7 @@ Foam::Istream& Foam::ISstream::read(string& str)
} }
// don't worry about a dangling backslash if string terminated prematurely // Don't worry about a dangling backslash if string terminated prematurely
buf[errLen] = buf[nChar] = '\0'; buf[errLen] = buf[nChar] = '\0';
FatalIOErrorInFunction(*this) FatalIOErrorInFunction(*this)
...@@ -711,6 +711,7 @@ Foam::Istream& Foam::ISstream::readVerbatim(string& str) ...@@ -711,6 +711,7 @@ Foam::Istream& Foam::ISstream::readVerbatim(string& str)
unsigned nChar = 0; unsigned nChar = 0;
char c; char c;
str.clear();
while (get(c)) while (get(c))
{ {
if (c == token::HASH) if (c == token::HASH)
...@@ -720,8 +721,7 @@ Foam::Istream& Foam::ISstream::readVerbatim(string& str) ...@@ -720,8 +721,7 @@ Foam::Istream& Foam::ISstream::readVerbatim(string& str)
if (nextC == token::END_BLOCK) if (nextC == token::END_BLOCK)
{ {
// The closing "#}" found // The closing "#}" found
buf[nChar] = '\0'; str.append(buf, nChar);
str = buf;
return *this; return *this;
} }
else else
...@@ -733,19 +733,13 @@ Foam::Istream& Foam::ISstream::readVerbatim(string& str) ...@@ -733,19 +733,13 @@ Foam::Istream& Foam::ISstream::readVerbatim(string& str)
buf[nChar++] = c; buf[nChar++] = c;
if (nChar == maxLen) if (nChar == maxLen)
{ {
buf[errLen] = '\0'; str.append(buf, nChar);
nChar = 0;
FatalIOErrorInFunction(*this)
<< "string \"" << buf << "...\"\n"
<< " is too long (max. " << maxLen << " characters)"
<< exit(FatalIOError);
return *this;
} }
} }
// don't worry about a dangling backslash if string terminated prematurely // Don't worry about a dangling backslash if string terminated prematurely
buf[errLen] = buf[nChar] = '\0'; buf[errLen] = buf[nChar] = '\0';
FatalIOErrorInFunction(*this) FatalIOErrorInFunction(*this)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment