From 8b877f7c3666ed91e6891b8608c7d0aabab71874 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Wed, 28 Sep 2016 01:56:29 -0700 Subject: [PATCH] libobs/util: Fix fread_utf8 not working with files < 3 bytes When it was checking for the BOM at the beginning of the file, it would just return out of the function if it didn't read at least 3 bytes. This would particularly affect text sources. --- libobs/util/platform.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libobs/util/platform.c b/libobs/util/platform.c index ffccf8ab2..8d8669ecc 100644 --- a/libobs/util/platform.c +++ b/libobs/util/platform.c @@ -164,7 +164,6 @@ size_t os_fread_mbs(FILE *file, char **pstr) size_t os_fread_utf8(FILE *file, char **pstr) { size_t size = 0; - size_t size_read; size_t len = 0; *pstr = NULL; @@ -177,11 +176,13 @@ size_t os_fread_utf8(FILE *file, char **pstr) char *utf8str; off_t offset; + bom[0] = 0; + bom[1] = 0; + bom[2] = 0; + /* remove the ghastly BOM if present */ fseek(file, 0, SEEK_SET); - size_read = fread(bom, 1, 3, file); - if (size_read != 3) - return 0; + fread(bom, 1, 3, file); offset = (astrcmp_n(bom, "\xEF\xBB\xBF", 3) == 0) ? 3 : 0;