*fixed a loading bug when importing a utf8 file.

This commit is contained in:
paladin-t 2016-04-29 17:37:29 +08:00
parent 85f429353e
commit ff7cd31fa7
3 changed files with 14 additions and 2 deletions

View File

@ -1,3 +1,6 @@
Apr. 29 2016
Fixed a loading bug when importing a UTF8 file
Apr. 26 2016
Added an invalid operation usage error when met an unexpected expression

View File

@ -4279,10 +4279,19 @@ static char* _load_file(mb_interpreter_t* s, const char* f, const char* prefix)
}
buf = (char*)mb_malloc((size_t)(l + 1));
mb_assert(buf);
if(prefix) {
if(prefix)
memcpy(buf, prefix, i);
}
fread(buf + i, 1, l, fp);
#ifdef MB_ENABLE_UNICODE
do {
char* off = buf + i;
int b = mb_uu_getbom(&off);
if(b) {
memmove(buf + i, buf + i + b, l - b - i);
buf[l - b] = _ZERO_CHAR;
}
} while(0);
#endif /* MB_ENABLE_UNICODE */
fclose(fp);
buf[l] = _ZERO_CHAR;
}

Binary file not shown.