From 9f37ad360ea1c32162f0cc1799b1b292594fc771 Mon Sep 17 00:00:00 2001 From: Steve Urquhart Date: Fri, 9 Feb 2024 15:14:12 -0500 Subject: [PATCH] Support files with UTF8BOM character --- StandAlone/StandAlone.cpp | 14 ++++++++++++++ Test/UTF8BOM.vert | 11 +++++++++++ Test/baseResults/UTF8BOM.vert.out | 1 + Test/runtests | 7 +++++++ 4 files changed, 33 insertions(+) create mode 100644 Test/UTF8BOM.vert create mode 100644 Test/baseResults/UTF8BOM.vert.out diff --git a/StandAlone/StandAlone.cpp b/StandAlone/StandAlone.cpp index 9cccdf6f..ac967f2b 100644 --- a/StandAlone/StandAlone.cpp +++ b/StandAlone/StandAlone.cpp @@ -2167,6 +2167,20 @@ char* ReadFileData(const char* fileName) fseek(in, 0, SEEK_SET); + if (count > 3) { + unsigned char head[3]; + if (fread(head, 1, 3, in) == 3) { + if (head[0] == 0xef && head[1] == 0xbb && head[2] == 0xbf) { + // skip BOM + count -= 3; + } else { + fseek(in, 0, SEEK_SET); + } + } else { + Error("can't read input file"); + } + } + char* return_data = (char*)malloc(count + 1); // freed in FreeFileData() if ((int)fread(return_data, 1, count, in) != count) { free(return_data); diff --git a/Test/UTF8BOM.vert b/Test/UTF8BOM.vert new file mode 100644 index 00000000..357cc54b --- /dev/null +++ b/Test/UTF8BOM.vert @@ -0,0 +1,11 @@ +/* + +glslangValidator.exe --glsl-version 410 -V -S vert -o UTF8BOM.vert.out UTF8BOM.vert + +*/ + +#version 110 + +void main() +{ +} diff --git a/Test/baseResults/UTF8BOM.vert.out b/Test/baseResults/UTF8BOM.vert.out new file mode 100644 index 00000000..19db13f6 --- /dev/null +++ b/Test/baseResults/UTF8BOM.vert.out @@ -0,0 +1 @@ +UTF8BOM.vert diff --git a/Test/runtests b/Test/runtests index d3c1646e..00c2babd 100755 --- a/Test/runtests +++ b/Test/runtests @@ -348,6 +348,13 @@ diff -b $BASEDIR/enhanced.7.link.out "$TARGETDIR/enhanced.7.link.out" || HASERRO run --enhanced-msgs -V --target-env vulkan1.2 --amb --aml spv.textureError.frag > "$TARGETDIR/spv.textureError.frag.out" diff -b $BASEDIR/spv.textureError.frag.out "$TARGETDIR/spv.textureError.frag.out" || HASERROR=1 +# +# Test UTF8BOM +# +echo "Testing UTF8BOM" +run --glsl-version 410 -V -S vert UTF8BOM.vert > $TARGETDIR/UTF8BOM.vert.out +diff -b $BASEDIR/UTF8BOM.vert.out $TARGETDIR/UTF8BOM.vert.out || HASERROR=1 + # # Final checking #