summaryrefslogtreecommitdiffstats
path: root/source/core
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2017-11-04 17:03:00 -0400
committerYong He <yonghe@outlook.com>2017-11-04 17:03:00 -0400
commit1f9686ce87573efdd4ad56040deb2d424fe51929 (patch)
tree1b4f3a050d91350e5d7243dc490420177cf70d9a /source/core
parentcb0a5773cd3b3564c4a19b85aaddd3d9cc63a3c7 (diff)
determineEncoding bug fix
Diffstat (limited to 'source/core')
-rw-r--r--source/core/text-io.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/source/core/text-io.cpp b/source/core/text-io.cpp
index 3e8301fa8..d0d0a3cc6 100644
--- a/source/core/text-io.cpp
+++ b/source/core/text-io.cpp
@@ -196,8 +196,11 @@ namespace Slang
bool HasNullBytes(char * str, int len)
{
- for (int i = 0; i < len; i++)
- if (str[len] == 0)
+ bool hasSeenNull = false;
+ for (int i = 0; i < len - 1; i++)
+ if (str[i] == 0)
+ hasSeenNull = true;
+ else if (hasSeenNull)
return true;
return false;
}
@@ -223,7 +226,9 @@ namespace Slang
{
// find null bytes
if (HasNullBytes(buffer.Buffer(), (int)buffer.Count()))
+ {
return Encoding::UTF16;
+ }
return Encoding::UTF8;
}
}
@@ -231,6 +236,7 @@ namespace Slang
void StreamReader::ReadBuffer()
{
buffer.SetSize(4096);
+ memset(buffer.Buffer(), 0, buffer.Count() * sizeof(buffer[0]));
auto len = stream->Read(buffer.Buffer(), buffer.Count());
buffer.SetSize((int)len);
ptr = 0;