aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorMartin Kiewitz2010-05-03 13:55:49 +0000
committerMartin Kiewitz2010-05-03 13:55:49 +0000
commit98aa8b195acb204587189c67f4e9eb306ee1ebc1 (patch)
treecadf8f35141f9b0944db5d903ac7efac0328723e /engines
parentb4d35b327945830968b127aedaf34b6c3c976d4d (diff)
downloadscummvm-rg350-98aa8b195acb204587189c67f4e9eb306ee1ebc1.tar.gz
scummvm-rg350-98aa8b195acb204587189c67f4e9eb306ee1ebc1.tar.bz2
scummvm-rg350-98aa8b195acb204587189c67f4e9eb306ee1ebc1.zip
SCI: fix possible heap error
svn-id: r48908
Diffstat (limited to 'engines')
-rw-r--r--engines/sci/engine/kfile.cpp17
1 files changed, 9 insertions, 8 deletions
diff --git a/engines/sci/engine/kfile.cpp b/engines/sci/engine/kfile.cpp
index 22abc4b193..e6b9a5388c 100644
--- a/engines/sci/engine/kfile.cpp
+++ b/engines/sci/engine/kfile.cpp
@@ -229,16 +229,17 @@ static void fgets_wrapper(EngineState *s, char *dest, int maxsize, int handle) {
error("fgets_wrapper: Trying to read from file '%s' opened for writing", f->_name.c_str());
return;
}
- if (maxsize > 1)
+ if (maxsize > 1) {
+ memset(dest, 0, maxsize);
f->_in->readLine(dest, maxsize);
- else
+ // The returned string must not have an ending LF
+ int strSize = strlen(dest);
+ if (strSize > 0) {
+ if (dest[strSize - 1] == 0x0A)
+ dest[strSize - 1] = 0;
+ }
+ } else {
*dest = f->_in->readByte();
-
- // The returned string must not have an ending LF
- int strSize = strlen(dest);
- if (strSize > 0) {
- if (dest[strSize - 1] == 0x0A)
- dest[strSize - 1] = 0;
}
debugC(2, kDebugLevelFile, "FGets'ed \"%s\"", dest);