From 3d81e11b49366b5636b8524ba0f8c7076e3fdf34 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Wed, 25 Oct 2017 11:33:09 +0100 Subject: mesa: remove unnecessary 'sort by year' for the GL extensions The sorting was originally added to work around broken games (comment says Quake3 demo) that were copying the extensions list into small buffer. Sorting does not solve the problem, since we'll still overflow and cause corruption/crash. Better workaround is to actually trim the string ... as done with a later commit which introduces the MESA_EXTENSION_MAX_YEAR env. variable. Side note: On my machine, the existing sorting makes no changes to the extensions string. Cc: Jose Fonseca Signed-off-by: Emil Velikov Reviewed-by: Brian Paul --- src/mesa/main/extensions.c | 53 +++------------------------------------------- 1 file changed, 3 insertions(+), 50 deletions(-) diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c index 2468e19bf99..7483b8f2496 100644 --- a/src/mesa/main/extensions.c +++ b/src/mesa/main/extensions.c @@ -352,30 +352,6 @@ _mesa_extension_supported(const struct gl_context *ctx, extension_index i) return (ctx->Version >= ext->version[ctx->API]) && base[ext->offset]; } -/** - * Compare two entries of the extensions table. Sorts first by year, - * then by name. - * - * Arguments are indices into _mesa_extension_table. - */ -static int -extension_compare(const void *p1, const void *p2) -{ - extension_index i1 = * (const extension_index *) p1; - extension_index i2 = * (const extension_index *) p2; - const struct mesa_extension *e1 = &_mesa_extension_table[i1]; - const struct mesa_extension *e2 = &_mesa_extension_table[i2]; - int res; - - res = (int)e1->year - (int)e2->year; - - if (res == 0) { - res = strcmp(e1->name, e2->name); - } - - return res; -} - /** * Construct the GL_EXTENSIONS string. Called the first time that @@ -391,7 +367,7 @@ _mesa_make_extension_string(struct gl_context *ctx) /* Number of extensions */ unsigned count; /* Indices of the extensions sorted by year */ - extension_index *extension_indices; + extension_index extension_indices[MESA_EXTENSION_COUNT]; /* String of extra extensions. */ const char *extra_extensions = get_extension_override(ctx); unsigned k; @@ -415,8 +391,8 @@ _mesa_make_extension_string(struct gl_context *ctx) if (i->year <= maxYear && _mesa_extension_supported(ctx, k)) { - length += strlen(i->name) + 1; /* +1 for space */ - ++count; + length += strlen(i->name) + 1; /* +1 for space */ + extension_indices[count++] = k; } } if (extra_extensions != NULL) @@ -427,28 +403,6 @@ _mesa_make_extension_string(struct gl_context *ctx) return NULL; } - extension_indices = malloc(count * sizeof(extension_index)); - if (extension_indices == NULL) { - free(exts); - return NULL; - } - - /* Sort extensions in chronological order because certain old applications - * (e.g., Quake3 demo) store the extension list in a static size buffer so - * chronologically order ensure that the extensions that such applications - * expect will fit into that buffer. - */ - j = 0; - for (k = 0; k < MESA_EXTENSION_COUNT; ++k) { - if (_mesa_extension_table[k].year <= maxYear && - _mesa_extension_supported(ctx, k)) { - extension_indices[j++] = k; - } - } - assert(j == count); - qsort(extension_indices, count, - sizeof *extension_indices, extension_compare); - /* Build the extension string.*/ for (j = 0; j < count; ++j) { const struct mesa_extension *i = &_mesa_extension_table[extension_indices[j]]; @@ -456,7 +410,6 @@ _mesa_make_extension_string(struct gl_context *ctx) strcat(exts, i->name); strcat(exts, " "); } - free(extension_indices); if (extra_extensions != 0) { strcat(exts, extra_extensions); } -- cgit v1.2.3