summaryrefslogtreecommitdiffstats
path: root/win/tkWinDialog.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2019-07-30 21:38:18 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2019-07-30 21:38:18 (GMT)
commitd1cee4ca466f149ff990f8bea8eaa7a50694e901 (patch)
tree31781b6b47b2c6b39c36d72b07cf2e1fd6a982bd /win/tkWinDialog.c
parent1ab87b68045ba6b3538301fd0d976bf4fbdd5d46 (diff)
downloadtk-d1cee4ca466f149ff990f8bea8eaa7a50694e901.zip
tk-d1cee4ca466f149ff990f8bea8eaa7a50694e901.tar.gz
tk-d1cee4ca466f149ff990f8bea8eaa7a50694e901.tar.bz2
Only free "patterns" once, not each time inside the loop. That might crash with long filters.
Diffstat (limited to 'win/tkWinDialog.c')
-rw-r--r--win/tkWinDialog.c80
1 files changed, 41 insertions, 39 deletions
diff --git a/win/tkWinDialog.c b/win/tkWinDialog.c
index 743720d..2701b82 100644
--- a/win/tkWinDialog.c
+++ b/win/tkWinDialog.c
@@ -2295,54 +2295,56 @@ static int MakeFilterVista(
for (i = 0, filterPtr = flist.filters;
filterPtr;
filterPtr = filterPtr->next, ++i) {
- const char *sep;
- FileFilterClause *clausePtr;
- int nbytes;
+ const char *sep;
+ FileFilterClause *clausePtr;
+ int nbytes;
- /* Check if this entry should be shown as the default */
- if (initial && strcmp(initial, filterPtr->name) == 0)
+ /* Check if this entry should be shown as the default */
+ if (initial && strcmp(initial, filterPtr->name) == 0)
initialIndex = i+1; /* Windows filter indices are 1-based */
- /* First stash away the text description of the pattern */
+ /* First stash away the text description of the pattern */
Tcl_WinUtfToTChar(filterPtr->name, -1, &ds);
- nbytes = Tcl_DStringLength(&ds); /* # bytes, not Unicode chars */
- nbytes += sizeof(WCHAR); /* Terminating \0 */
- dlgFilterPtr[i].pszName = ckalloc(nbytes);
- memmove((void *) dlgFilterPtr[i].pszName, Tcl_DStringValue(&ds), nbytes);
- Tcl_DStringFree(&ds);
+ nbytes = Tcl_DStringLength(&ds); /* # bytes, not Unicode chars */
+ nbytes += sizeof(WCHAR); /* Terminating \0 */
+ dlgFilterPtr[i].pszName = ckalloc(nbytes);
+ memmove((void *) dlgFilterPtr[i].pszName, Tcl_DStringValue(&ds), nbytes);
+ Tcl_DStringFree(&ds);
- /*
- * Loop through and join patterns with a ";" Each "clause"
- * corresponds to a single textual description (called typename)
- * in the tk_getOpenFile docs. Each such typename may occur
- * multiple times and all these form a single filter entry
- * with one clause per occurence. Further each clause may specify
- * multiple patterns. Hence the nested loop here.
- */
- sep = "";
- for (clausePtr=filterPtr->clauses ; clausePtr;
- clausePtr=clausePtr->next) {
- GlobPattern *globPtr;
- for (globPtr = clausePtr->patterns; globPtr;
- globPtr = globPtr->next) {
- Tcl_DStringAppend(&patterns, sep, -1);
- Tcl_DStringAppend(&patterns, globPtr->pattern, -1);
- sep = ";";
- }
- }
+ /*
+ * Loop through and join patterns with a ";" Each "clause"
+ * corresponds to a single textual description (called typename)
+ * in the tk_getOpenFile docs. Each such typename may occur
+ * multiple times and all these form a single filter entry
+ * with one clause per occurence. Further each clause may specify
+ * multiple patterns. Hence the nested loop here.
+ */
+ sep = "";
+ for (clausePtr=filterPtr->clauses ; clausePtr;
+ clausePtr=clausePtr->next) {
+ GlobPattern *globPtr;
+ for (globPtr = clausePtr->patterns; globPtr;
+ globPtr = globPtr->next) {
+ Tcl_DStringAppend(&patterns, sep, -1);
+ Tcl_DStringAppend(&patterns, globPtr->pattern, -1);
+ sep = ";";
+ }
+ }
- /* Again we need a Unicode form of the string */
+ /* Again we need a Unicode form of the string */
Tcl_WinUtfToTChar(Tcl_DStringValue(&patterns), -1, &ds);
- nbytes = Tcl_DStringLength(&ds); /* # bytes, not Unicode chars */
- nbytes += sizeof(WCHAR); /* Terminating \0 */
- dlgFilterPtr[i].pszSpec = ckalloc(nbytes);
- memmove((void *)dlgFilterPtr[i].pszSpec, Tcl_DStringValue(&ds), nbytes);
- Tcl_DStringFree(&ds);
- Tcl_DStringFree(&patterns);
+ nbytes = Tcl_DStringLength(&ds); /* # bytes, not Unicode chars */
+ nbytes += sizeof(WCHAR); /* Terminating \0 */
+ dlgFilterPtr[i].pszSpec = ckalloc(nbytes);
+ memmove((void *)dlgFilterPtr[i].pszSpec, Tcl_DStringValue(&ds), nbytes);
+ Tcl_DStringFree(&ds);
+ Tcl_DStringSetLength(&patterns, 0);
}
+ Tcl_DStringFree(&patterns);
- if (initialIndex == 0)
- initialIndex = 1; /* If no default, show first entry */
+ if (initialIndex == 0) {
+ initialIndex = 1; /* If no default, show first entry */
+ }
*initialIndexPtr = initialIndex;
*dlgFilterPtrPtr = dlgFilterPtr;
*countPtr = flist.numFilters;