Skip to content

Commit

Permalink
Fix [3981091e] Segmentation fault with bogus resource value (X11)
Browse files Browse the repository at this point in the history
  • Loading branch information
jan.nijtmans committed Sep 20, 2024
2 parents 116741c + d8be6f2 commit 24b099e
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions generic/ttk/ttkTheme.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Tcl_Obj *Ttk_StyleMap(Ttk_Style style, const char *optionName, Ttk_State state)

/*
* Ttk_StyleDefault --
* Look up default resource setting the in the specified style.
* Look up default resource setting in the specified style.
*/
Tcl_Obj *Ttk_StyleDefault(Ttk_Style style, const char *optionName)
{
Expand Down Expand Up @@ -216,7 +216,7 @@ GetOptionMap(Ttk_ElementClass *elementClass, Tk_OptionTable optionTable)
* from the specified element specification.
*/
static Ttk_ElementClass *
NewElementClass(const char *name, Ttk_ElementSpec *specPtr,void *clientData)
NewElementClass(const char *name, Ttk_ElementSpec *specPtr, void *clientData)
{
Ttk_ElementClass *elementClass = (Ttk_ElementClass *)ckalloc(sizeof(Ttk_ElementClass));
int i;
Expand All @@ -237,7 +237,7 @@ NewElementClass(const char *name, Ttk_ElementSpec *specPtr,void *clientData)
elementClass->defaultValues = (Tcl_Obj **)
ckalloc(elementClass->nResources * sizeof(Tcl_Obj *) + 1);
for (i=0; i < elementClass->nResources; ++i) {
const char *defaultValue = specPtr->options[i].defaultValue;
const char *defaultValue = specPtr->options[i].defaultValue;
if (defaultValue) {
elementClass->defaultValues[i] = Tcl_NewStringObj(defaultValue,-1);
Tcl_IncrRefCount(elementClass->defaultValues[i]);
Expand Down Expand Up @@ -407,7 +407,7 @@ typedef struct
* Cleanup procedure for StylePackageData.
*/
static void Ttk_StylePkgFree(
ClientData clientData,
void *clientData,
TCL_UNUSED(Tcl_Interp *))
{
StylePackageData *pkgPtr = (StylePackageData *)clientData;
Expand Down Expand Up @@ -475,7 +475,7 @@ static StylePackageData *GetStylePackageData(Tcl_Interp *interp)
*
*/
void Ttk_RegisterCleanup(
Tcl_Interp *interp, ClientData clientData, Ttk_CleanupProc *cleanupProc)
Tcl_Interp *interp, void *clientData, Ttk_CleanupProc *cleanupProc)
{
StylePackageData *pkgPtr = GetStylePackageData(interp);
Cleanup *cleanup = (Cleanup *)ckalloc(sizeof(*cleanup));
Expand All @@ -498,7 +498,7 @@ void Ttk_RegisterCleanup(
* the widget hierarchy, so this is done by evaluating a Tcl script.
*/

static void ThemeChangedProc(ClientData clientData)
static void ThemeChangedProc(void *clientData)
{
static char ThemeChangedScript[] = "ttk::ThemeChanged";
StylePackageData *pkgPtr = (StylePackageData *)clientData;
Expand Down Expand Up @@ -534,9 +534,10 @@ void Ttk_TkDestroyedHandler(
StylePackageData* pkgPtr = GetStylePackageData(interp);

/*
* Cancel any pending ThemeChanged calls:
* Cancel any pending ThemeChanged calls. We might be called
* before Ttk is initialized. See bug [3981091ed336].
*/
if (pkgPtr->themeChangePending) {
if (pkgPtr && pkgPtr->themeChangePending) {
Tcl_CancelIdleCall(ThemeChangedProc, pkgPtr);
}
}
Expand Down Expand Up @@ -1188,7 +1189,7 @@ static Tcl_Obj* HashTableToDict(Tcl_HashTable *ht)
*/
static int
StyleMapCmd(
ClientData clientData, /* StylePackageData pointer */
void *clientData, /* StylePackageData pointer */
Tcl_Interp *interp, /* Current interpreter */
int objc, /* Number of arguments */
Tcl_Obj *const objv[]) /* Argument objects */
Expand Down Expand Up @@ -1255,7 +1256,7 @@ StyleMapCmd(
/* + style configure $style -option ?value...
*/
static int StyleConfigureCmd(
ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
void *clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
StylePackageData *pkgPtr = (StylePackageData *)clientData;
Ttk_Theme theme = pkgPtr->currentTheme;
Expand All @@ -1272,10 +1273,10 @@ static int StyleConfigureCmd(
styleName = Tcl_GetString(objv[2]);
stylePtr = Ttk_GetStyle(theme, styleName);

if (objc == 3) { /* style default $styleName */
if (objc == 3) { /* style configure $styleName */
Tcl_SetObjResult(interp, HashTableToDict(&stylePtr->defaultsTable));
return TCL_OK;
} else if (objc == 4) { /* style default $styleName -option */
} else if (objc == 4) { /* style configure $styleName -option */
const char *optionName = Tcl_GetString(objv[3]);
Tcl_HashEntry *entryPtr =
Tcl_FindHashEntry(&stylePtr->defaultsTable, optionName);
Expand Down Expand Up @@ -1310,7 +1311,7 @@ static int StyleConfigureCmd(
/* + style lookup $style -option ?statespec? ?defaultValue?
*/
static int StyleLookupCmd(
ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
void *clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
StylePackageData *pkgPtr = (StylePackageData *)clientData;
Ttk_Theme theme = pkgPtr->currentTheme;
Expand Down Expand Up @@ -1352,7 +1353,7 @@ static int StyleLookupCmd(
}

static int StyleThemeCurrentCmd(
ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj * const objv[])
void *clientData, Tcl_Interp *interp, int objc, Tcl_Obj * const objv[])
{
StylePackageData *pkgPtr = (StylePackageData *)clientData;
Tcl_HashSearch search;
Expand Down Expand Up @@ -1388,7 +1389,7 @@ static int StyleThemeCurrentCmd(
/* + style theme create name ?-parent $theme? ?-settings { script }?
*/
static int StyleThemeCreateCmd(
ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
void *clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
StylePackageData *pkgPtr = (StylePackageData *)clientData;
static const char *const optStrings[] =
Expand Down Expand Up @@ -1452,10 +1453,10 @@ static int StyleThemeCreateCmd(
* Return list of registered themes.
*/
static int StyleThemeNamesCmd(
ClientData clientData,
void *clientData,
Tcl_Interp *interp,
TCL_UNUSED(int),
TCL_UNUSED(Tcl_Obj *const *))
TCL_UNUSED(int), /* objc */
TCL_UNUSED(Tcl_Obj *const *)) /* objv */
{
StylePackageData *pkgPtr = (StylePackageData *)clientData;

Expand All @@ -1469,7 +1470,7 @@ static int StyleThemeNamesCmd(
*/
static int
StyleThemeSettingsCmd(
ClientData clientData, /* StylePackageData pointer */
void *clientData, /* StylePackageData pointer */
Tcl_Interp *interp, /* Current interpreter */
int objc, /* Number of arguments */
Tcl_Obj *const objv[]) /* Argument objects */
Expand Down Expand Up @@ -1498,7 +1499,7 @@ StyleThemeSettingsCmd(
/* + style element create name type ? ...args ?
*/
static int StyleElementCreateCmd(
ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
void *clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
StylePackageData *pkgPtr = (StylePackageData *)clientData;
Ttk_Theme theme = pkgPtr->currentTheme;
Expand Down Expand Up @@ -1533,7 +1534,7 @@ static int StyleElementCreateCmd(
* Return a list of elements defined in the current theme.
*/
static int StyleElementNamesCmd(
ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
void *clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
StylePackageData *pkgPtr = (StylePackageData *)clientData;
Ttk_Theme theme = pkgPtr->currentTheme;
Expand All @@ -1549,7 +1550,7 @@ static int StyleElementNamesCmd(
* Return list of element options for specified element
*/
static int StyleElementOptionsCmd(
ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
void *clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
StylePackageData *pkgPtr = (StylePackageData *)clientData;
Ttk_Theme theme = pkgPtr->currentTheme;
Expand Down Expand Up @@ -1587,7 +1588,7 @@ static int StyleElementOptionsCmd(
/* + style layout name ?spec?
*/
static int StyleLayoutCmd(
ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
void *clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
StylePackageData *pkgPtr = (StylePackageData *)clientData;
Ttk_Theme theme = pkgPtr->currentTheme;
Expand Down Expand Up @@ -1627,7 +1628,7 @@ static int StyleLayoutCmd(
*/
static int
StyleThemeUseCmd(
ClientData clientData, /* StylePackageData pointer */
void *clientData, /* StylePackageData pointer */
Tcl_Interp *interp, /* Current interpreter */
int objc, /* Number of arguments */
Tcl_Obj *const objv[]) /* Argument objects */
Expand Down Expand Up @@ -1684,7 +1685,7 @@ static const Ttk_Ensemble StyleEnsemble[] = {

static int
StyleObjCmd(
ClientData clientData, /* StylePackageData pointer */
void *clientData, /* StylePackageData pointer */
Tcl_Interp *interp, /* Current interpreter */
int objc, /* Number of arguments */
Tcl_Obj *const objv[]) /* Argument objects */
Expand Down

0 comments on commit 24b099e

Please sign in to comment.