diff options
author | Cody Northrop <[email protected]> | 2014-06-05 11:27:51 -0600 |
---|---|---|
committer | Courtney Goeltzenleuchter <[email protected]> | 2014-06-10 10:45:31 -0600 |
commit | 3eef571cbc3a311f32372ab9d1310ed787f9cfbd (patch) | |
tree | 1a5f94cf838edf3153ea8891a4e3f975c3c90a15 /src/mesa/main/shaderapi.c | |
parent | 2d399bb1837e01856c8e489aa5ec439ce9a1fdbc (diff) |
mesa: Fix substitution of large shaders
Signed-off-by: Cody Northrop <[email protected]>
Reviewed-by: Brian Paul <[email protected]>
Diffstat (limited to 'src/mesa/main/shaderapi.c')
-rw-r--r-- | src/mesa/main/shaderapi.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c index 28739daeb97..2ec2444daa2 100644 --- a/src/mesa/main/shaderapi.c +++ b/src/mesa/main/shaderapi.c @@ -1392,7 +1392,7 @@ _mesa_LinkProgram(GLhandleARB programObj) static GLcharARB * read_shader(const char *fname) { - const int max = 50*1000; + int shader_size = 0; FILE *f = fopen(fname, "r"); GLcharARB *buffer, *shader; int len; @@ -1401,8 +1401,19 @@ read_shader(const char *fname) return NULL; } - buffer = malloc(max); - len = fread(buffer, 1, max, f); + /* allocate enough room for the entire shader */ + fseek(f, 0, SEEK_END); + shader_size = ftell(f); + rewind(f); + assert(shader_size); + + /* add one for terminating zero */ + shader_size++; + + buffer = malloc(shader_size); + assert(buffer); + + len = fread(buffer, 1, shader_size, f); buffer[len] = 0; fclose(f); |