Browse Source

Fix UTF-8 signature detection

The signature detection code when reading UTF-8 files was causing the
UTF-8 strings read from file to allocate more data than they were
supposed to, causing the last 3 bytes to be garbage
jp9000 11 years ago
parent
commit
20fd2c82dc
1 changed files with 3 additions and 1 deletions
  1. 3 1
      libobs/util/platform.c

+ 3 - 1
libobs/util/platform.c

@@ -108,7 +108,7 @@ size_t os_fread_utf8(FILE *file, char **pstr)
 
 
 	if (size > 0) {
 	if (size > 0) {
 		char bom[3];
 		char bom[3];
-		char *utf8str = bmalloc(size+1);
+		char *utf8str;
 		off_t offset;
 		off_t offset;
 
 
 		/* remove the ghastly BOM if present */
 		/* remove the ghastly BOM if present */
@@ -116,6 +116,8 @@ size_t os_fread_utf8(FILE *file, char **pstr)
 		fread(bom, 1, 3, file);
 		fread(bom, 1, 3, file);
 		offset = (astrcmp_n(bom, "\xEF\xBB\xBF", 3) == 0) ? 3 : 0;
 		offset = (astrcmp_n(bom, "\xEF\xBB\xBF", 3) == 0) ? 3 : 0;
 
 
+		size -= offset;
+		utf8str = bmalloc(size+1);
 		fseeko(file, offset, SEEK_SET);
 		fseeko(file, offset, SEEK_SET);
 		fread(utf8str, 1, size, file);
 		fread(utf8str, 1, size, file);
 		utf8str[size] = 0;
 		utf8str[size] = 0;