--- src/mesa/main/arbprogram.c.original 2016-11-07 20:54:33.000000000 +0000 +++ src/mesa/main/arbprogram.c 2016-11-07 20:58:16.000000000 +0000 @@ -388,11 +388,13 @@ const char *capture_path = _mesa_get_shader_capture_path(); if (capture_path != NULL) { FILE *file; - char filename[PATH_MAX]; + char *filename; const char *shader_type = target == GL_FRAGMENT_PROGRAM_ARB ? "fragment" : "vertex"; + size_t len = strlen(capture_path) + 1 + 1 + 2 + 10 + 12 + 1; + filename = malloc(len); - _mesa_snprintf(filename, sizeof(filename), "%s/%cp-%u.shader_test", + _mesa_snprintf(filename, len, "%s/%cp-%u.shader_test", capture_path, shader_type[0], base->Id); file = fopen(filename, "w"); if (file) { @@ -403,6 +405,7 @@ } else { _mesa_warning(ctx, "Failed to open %s", filename); } + free(filename); } } --- src/mesa/main/shaderapi.c.original 2016-11-07 21:05:45.000000000 +0000 +++ src/mesa/main/shaderapi.c 2016-11-07 21:13:34.000000000 +0000 @@ -112,6 +112,7 @@ if (!read_env_var) { path = getenv("MESA_SHADER_CAPTURE_PATH"); read_env_var = true; +#ifdef PATH_MAX if (path && strlen(path) > PATH_MAX - strlen("/fp-4294967295.shader_test")) { GET_CURRENT_CONTEXT(ctx); @@ -119,6 +120,7 @@ "request to capture shaders"); path = NULL; } +#endif } return path; @@ -1101,9 +1103,11 @@ const char *capture_path = _mesa_get_shader_capture_path(); if (shProg->Name != 0 && shProg->Name != ~0 && capture_path != NULL) { FILE *file; - char filename[PATH_MAX]; + char *filename; + size_t len = strlen(capture_path) + 1 + 10 + 12 + 1; - _mesa_snprintf(filename, sizeof(filename), "%s/%u.shader_test", + filename = malloc(len); + _mesa_snprintf(filename, len, "%s/%u.shader_test", capture_path, shProg->Name); file = fopen(filename, "w"); @@ -1124,6 +1128,7 @@ } else { _mesa_warning(ctx, "Failed to open %s", filename); } + free(filename); } if (shProg->LinkStatus == GL_FALSE && @@ -1618,18 +1623,25 @@ * * /_.glsl */ -static void +static char * construct_name(const gl_shader_stage stage, const char *source, - const char *path, char *name, unsigned length) + const char *path) { char sha[64]; static const char *types[] = { "VS", "TC", "TE", "GS", "FS", "CS", }; + char *name; + size_t length; generate_sha1(source, sha); + + length = strlen(path) + 1 + 2 + 1 + strlen(sha) + 5 + 1; + name = malloc(length); + _mesa_snprintf(name, length, "%s/%s_%s.glsl", path, types[stage], sha); + return name; } /** @@ -1638,7 +1650,7 @@ static void dump_shader(const gl_shader_stage stage, const char *source) { - char name[PATH_MAX]; + char *name; static bool path_exists = true; char *dump_path; FILE *f; @@ -1652,7 +1664,7 @@ return; } - construct_name(stage, source, dump_path, name, PATH_MAX); + name = construct_name(stage, source, dump_path); f = fopen(name, "w"); if (f) { @@ -1663,6 +1675,7 @@ _mesa_warning(ctx, "could not open %s for dumping shader (%s)", name, strerror(errno)); } + free(name); } /** @@ -1672,7 +1685,7 @@ static GLcharARB * read_shader(const gl_shader_stage stage, const char *source) { - char name[PATH_MAX]; + char *name; char *read_path; static bool path_exists = true; int len, shader_size = 0; @@ -1688,9 +1701,10 @@ return NULL; } - construct_name(stage, source, read_path, name, PATH_MAX); + name = construct_name(stage, source, read_path); f = fopen(name, "r"); + free(name); if (!f) return NULL;