Yeah, that's a good point.  I'll get rid of that too.

-Brian

On 04/28/2014 03:37 PM, Jamey Sharp wrote:
After this patch, you don't need the stat call either, right? I think
the function reduces to getenv, snprintf, piglit_load_text_file,
piglit_compile_shader_text, and free. Which seems like a good idea
even if it wasn't fixing any bugs.

Jamey

On Mon, Apr 28, 2014 at 2:13 PM, Brian Paul <[email protected]> wrote:
The old code had a problem on MinGW.  If the shader/text file had
DOS-style \r\n line endings, fread() would convert them to Unix-style
\n line endings.  Since the actual number of chars read by fread()
was less than the stat()'d size, we put the terminating '\0' in the
wrong place, possibly after some garbage characters in the buffer.

This sometimes caused the GLSL compiler to generate an error when it
found those garbage chars.

A Heisenbug:  I was seeing failures w/out gdb but success w/ gdb. Ugh!
---
  tests/util/piglit-shader.c |   16 +++-------------
  1 file changed, 3 insertions(+), 13 deletions(-)

diff --git a/tests/util/piglit-shader.c b/tests/util/piglit-shader.c
index b326abd..0aa4d02 100644
--- a/tests/util/piglit-shader.c
+++ b/tests/util/piglit-shader.c
@@ -69,7 +69,6 @@ piglit_compile_shader(GLenum target, const char *filename)
         struct stat st;
         int err;
         GLchar *prog_string;
-       FILE *f;
         const char *source_dir;
         char filename_with_path[FILENAME_MAX];

@@ -89,21 +88,12 @@ piglit_compile_shader(GLenum target, const char *filename)
                 exit(1);
         }

-       prog_string = malloc(st.st_size + 1);
-       if (prog_string == NULL) {
-               fprintf(stderr, "malloc\n");
+       prog_string = piglit_load_text_file(filename_with_path, NULL);
+       if (!prog_string) {
+               fprintf(stderr, "Unable to read %s\n", filename_with_path);
                 exit(1);
         }

-       f = fopen(filename_with_path, "r");
-       if (f == NULL) {
-               fprintf(stderr, "Couldn't open program: %s\n", strerror(errno));
-               exit(1);
-       }
-       fread(prog_string, 1, st.st_size, f);
-       prog_string[st.st_size] = '\0';
-       fclose(f);
-
         prog = piglit_compile_shader_text(target, prog_string);

         free(prog_string);
--
1.7.10.4

_______________________________________________
Piglit mailing list
[email protected]
https://urldefense.proofpoint.com/v1/url?u=http://lists.freedesktop.org/mailman/listinfo/piglit&k=oIvRg1%2BdGAgOoM1BIlLLqw%3D%3D%0A&r=lGQMzzTgII0I7jefp2FHq7WtZ%2BTLs8wadB%2BiIj9xpBY%3D%0A&m=oLWRJcnowivMFiIF8%2FG4JcEfX8HtT6%2F77%2Fc%2BogvQnEo%3D%0A&s=1a9d7ad89c05f0c93ab43d7febd772319ea2e2aee0fbeb83c605a7422f3ddcb1

_______________________________________________
Piglit mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/piglit

Reply via email to