summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--macosx/tkMacOSXDialog.c68
2 files changed, 31 insertions, 44 deletions
diff --git a/ChangeLog b/ChangeLog
index 3326c50..b31b592 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2005-02-22 Daniel Steffen <das@users.sourceforge.net>
+
+ * macosx/tkMacOSXDialog.c (Tk_GetSaveFileObjCmd, NavServicesGetFile):
+ fixed encoding problems with -initialfile & -filetypes and
+ corrected potential buffer overrun with -initialdir/-initialfile.
+ [Bug 1146057]
+
2005-02-14 Donal K. Fellows <donal.k.fellows@man.ac.uk>
* tests/all.tcl: Add a [package require Tk] so that a missing
diff --git a/macosx/tkMacOSXDialog.c b/macosx/tkMacOSXDialog.c
index 074dca6..736a879 100644
--- a/macosx/tkMacOSXDialog.c
+++ b/macosx/tkMacOSXDialog.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkMacOSXDialog.c,v 1.4.2.2 2004/02/16 00:42:34 wolfsuit Exp $
+ * RCS: @(#) $Id: tkMacOSXDialog.c,v 1.4.2.3 2005/02/22 08:49:14 das Exp $
*/
#include <Carbon/Carbon.h>
@@ -81,7 +81,7 @@ pascal void OpenEventProc(NavEventCallbackMessage callBackSelector,
static void InitFileDialogs();
static int NavServicesGetFile(Tcl_Interp *interp, OpenFileData *ofd,
AEDesc *initialDescPtr,
- unsigned char *initialFile, AEDescList *selectDescPtr,
+ char *initialFile, AEDescList *selectDescPtr,
CFStringRef title, CFStringRef message, int multiple, int isOpen);
static int HandleInitialDirectory (Tcl_Interp *interp,
char *initialFile, char *initialDir,
@@ -415,7 +415,7 @@ Tk_GetSaveFileObjCmd(
Tcl_Obj *CONST objv[]) /* Argument objects. */
{
int i, result;
- Str255 initialFile;
+ char *initialFile = NULL;
Tk_Window parent;
AEDesc initialDesc = {typeNull, NULL};
AEDesc *initialPtr = NULL;
@@ -437,7 +437,6 @@ Tk_GetSaveFileObjCmd(
result = TCL_ERROR;
parent = (Tk_Window) clientData;
- StrLength(initialFile) = 0;
title = NULL;
message = NULL;
@@ -445,8 +444,6 @@ Tk_GetSaveFileObjCmd(
char *choice;
int index, choiceLen;
char *string;
- Tcl_DString ds;
- int srcRead, dstWrote;
if (Tcl_GetIndexFromObj(interp, objv[i], saveOptionStrings, "option",
TCL_EXACT, &index) != TCL_OK) {
@@ -473,16 +470,7 @@ Tk_GetSaveFileObjCmd(
}
break;
case SAVE_INITFILE:
- choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen);
- if (Tcl_TranslateFileName(interp, choice, &ds) == NULL) {
- result = TCL_ERROR;
- goto end;
- }
- Tcl_UtfToExternal(NULL, TkMacOSXCarbonEncoding, Tcl_DStringValue(&ds),
- Tcl_DStringLength(&ds), 0, NULL,
- StrBody(initialFile), 255, &srcRead, &dstWrote, NULL);
- StrLength(initialFile) = (unsigned char) dstWrote;
- Tcl_DStringFree(&ds);
+ initialFile = Tcl_GetStringFromObj(objv[i + 1], NULL);
break;
case SAVE_MESSAGE:
choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen);
@@ -734,7 +722,7 @@ NavServicesGetFile(
Tcl_Interp *interp,
OpenFileData *ofdPtr,
AEDesc *initialDescPtr,
- unsigned char *initialFile,
+ char *initialFile,
AEDescList *selectDescPtr,
CFStringRef title,
CFStringRef message,
@@ -748,9 +736,7 @@ NavServicesGetFile(
OSErr err;
Tcl_Obj *theResult = NULL;
int result;
- TextEncoding encoding;
- encoding = GetApplicationTextEncoding();
err = NavGetDefaultDialogCreationOptions(&diagOptions);
if (err!=noErr) {
return TCL_ERROR;
@@ -784,7 +770,7 @@ NavServicesGetFile(
for (filterPtr = ofdPtr->fl.filters; filterPtr != NULL;
filterPtr = filterPtr->next, index++) {
menuItemNames[index] = CFStringCreateWithCString(NULL,
- filterPtr->name, encoding);
+ filterPtr->name, kCFStringEncodingUTF8);
}
diagOptions.popupExtension = CFArrayCreate(NULL,
(const void **) menuItemNames, ofdPtr->fl.numFilters, NULL);
@@ -800,12 +786,12 @@ NavServicesGetFile(
diagOptions.optionFlags += kNavSupportPackages;
- diagOptions.clientName = CFStringCreateWithCString(NULL, "Wish", encoding);
+ diagOptions.clientName = CFStringCreateWithCString(NULL, "Wish", kCFStringEncodingUTF8);
diagOptions.message = message;
diagOptions.windowTitle = title;
- if ((initialFile != NULL) && (initialFile[0] != 0)) {
- diagOptions.saveFileName = CFStringCreateWithPascalString(NULL,
- initialFile, encoding);
+ if (initialFile) {
+ diagOptions.saveFileName = CFStringCreateWithCString(NULL,
+ initialFile, kCFStringEncodingUTF8);
} else {
diagOptions.saveFileName = NULL;
}
@@ -882,7 +868,6 @@ NavServicesGetFile(
if (theReply.validRecord && err == noErr) {
AEDesc resultDesc;
long count;
- Tcl_DString fileName;
FSRef fsRef;
char pathPtr[1024];
int pathValid = 0;
@@ -906,10 +891,14 @@ NavServicesGetFile(
char saveName [1024];
if (saveNameRef = NavDialogGetSaveFileName(dialogRef)) {
if (CFStringGetCString(saveNameRef, saveName,
- 1024, encoding)) {
- strcat(pathPtr, "/");
- strcat(pathPtr, saveName);
- pathValid = 1;
+ 1024, kCFStringEncodingUTF8)) {
+ if (strlen(pathPtr) + strlen(saveName) < 1023) {
+ strcat(pathPtr, "/");
+ strcat(pathPtr, saveName);
+ pathValid = 1;
+ } else {
+ fprintf(stderr, "Path name too long\n");
+ }
} else {
fprintf(stderr, "CFStringGetCString failed\n");
}
@@ -920,21 +909,12 @@ NavServicesGetFile(
pathValid = 1;
}
if (pathValid) {
- /*
- * Tested this and NULL=utf-8 encoding is
- * good here
- */
- Tcl_ExternalToUtfDString(NULL, pathPtr, -1,
- &fileName);
if (multiple) {
Tcl_ListObjAppendElement(interp, theResult,
- Tcl_NewStringObj(Tcl_DStringValue(&fileName),
- Tcl_DStringLength(&fileName)));
+ Tcl_NewStringObj(pathPtr, -1));
} else {
- Tcl_SetStringObj(theResult, Tcl_DStringValue(&fileName),
- Tcl_DStringLength(&fileName));
+ Tcl_SetStringObj(theResult, pathPtr, -1);
}
- Tcl_DStringFree(&fileName);
}
}
}
@@ -1316,9 +1296,9 @@ Tk_MessageBoxObjCmd(
int result = TCL_OK;
static CONST char *movableAlertStrings[] = {
- "-default", /* "-finemessage", */ "-icon",
+ "-default", /* "-detail", */ "-icon",
"-message", "-parent",
- "-title", "-type",
+ "-title", "-type",
(char *)NULL
};
static CONST char *movableTypeStrings[] = {
@@ -1337,7 +1317,7 @@ Tk_MessageBoxObjCmd(
(char *)NULL
};
enum movableAlertOptions {
- ALERT_DEFAULT, /* ALERT_FINEMESSAGE, */ ALERT_ICON,
+ ALERT_DEFAULT, /* ALERT_DETAIL, */ ALERT_ICON,
ALERT_MESSAGE, ALERT_PARENT,
ALERT_TITLE, ALERT_TYPE
};
@@ -1422,7 +1402,7 @@ Tk_MessageBoxObjCmd(
indexDefaultOption = i;
break;
-/* case ALERT_FINEMESSAGE:
+/* case ALERT_DETAIL:
str = Tcl_GetStringFromObj( objv[i + 1], NULL );
finemessageTextCF = CFStringCreateWithCString( NULL, str, kCFStringEncodingUTF8 );
break;