From 7c6c0958c653f1d01aac461a42154613ad44f926 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Fri, 1 Sep 2023 15:29:36 +0000 Subject: more progress strtod -> Tcl_GetDouble() --- generic/tkArgv.c | 7 +------ generic/tkCanvLine.c | 23 +++++++++++++++-------- generic/tkImgListFormat.c | 4 +--- win/tkWinGDI.c | 6 +----- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/generic/tkArgv.c b/generic/tkArgv.c index 1a3244a..be48694 100644 --- a/generic/tkArgv.c +++ b/generic/tkArgv.c @@ -215,12 +215,7 @@ Tk_ParseArgv( if (argc == 0) { goto missingArg; } - *((double *) infoPtr->dst) = strtod(argv[srcIndex], &endPtr); - if ((endPtr == argv[srcIndex]) || (*endPtr != 0)) { - Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "expected %s argument for \"%s\" but got \"%s\"", - "floating-point", infoPtr->key, argv[srcIndex])); - Tcl_SetErrorCode(interp, "TK", "ARG", "FLOAT", curArg, NULL); + if (Tcl_GetDouble(interp, argv[srcIndex], ((double *) infoPtr->dst)) != TCL_OK) { return TCL_ERROR; } srcIndex++; diff --git a/generic/tkCanvLine.c b/generic/tkCanvLine.c index 5e75837..8f2595f 100644 --- a/generic/tkCanvLine.c +++ b/generic/tkCanvLine.c @@ -1873,7 +1873,7 @@ GetLineIndex( { Tcl_Size idx, length; LineItem *linePtr = (LineItem *) itemPtr; - const char *string; + char *string; if (TCL_OK == TkGetIntForIndex(obj, 2*linePtr->numPoints - 1, 1, &idx)) { if (idx < 0) { @@ -1892,17 +1892,24 @@ GetLineIndex( if (string[0] == '@') { int i; double x, y, bestDist, dist, *coordPtr; - char *end; - const char *p; + char savechar; + char *p, *sep; p = string+1; - x = strtod(p, &end); - if ((end == p) || (*end != ',')) { + sep = strchr(p, ','); + if (!sep) { goto badIndex; } - p = end+1; - y = strtod(p, &end); - if ((end == p) || (*end != 0)) { + savechar = *sep; + *sep = '\0'; + i = Tcl_GetDouble(NULL, p, &x); + *sep = savechar; + if (i != TCL_OK) { + goto badIndex; + } + p = sep+1; + i = Tcl_GetDouble(NULL, p, &y); + if (i != TCL_OK) { goto badIndex; } bestDist = 1.0e36; diff --git a/generic/tkImgListFormat.c b/generic/tkImgListFormat.c index 974f4f4..4d3010f 100644 --- a/generic/tkImgListFormat.c +++ b/generic/tkImgListFormat.c @@ -1001,7 +1001,6 @@ ParseColorAsStandard( XColor parsedColor; const char *suffixString, *colorString; char colorBuffer[TK_PHOTO_MAX_COLOR_LENGTH + 1]; - char *tmpString; double fracAlpha; unsigned int suffixAlpha; int i; @@ -1047,8 +1046,7 @@ ParseColorAsStandard( suffixAlpha = 255; break; case '@': - fracAlpha = strtod(suffixString + 1, &tmpString); - if (*tmpString != '\0') { + if (Tcl_GetDouble(NULL, suffixString + 1, &fracAlpha) != TCL_OK) { Tcl_SetObjResult(interp, Tcl_ObjPrintf("invalid alpha " "suffix \"%s\": expected floating-point value", suffixString)); diff --git a/win/tkWinGDI.c b/win/tkWinGDI.c index 8b1bbff..f05bebc 100644 --- a/win/tkWinGDI.c +++ b/win/tkWinGDI.c @@ -2142,11 +2142,7 @@ static int GdiCopyBits( } } else if (strcmp(argv[k], "-scale") == 0) { if (argv[++k]) { - scale = strtod(argv[k], &strend); - if (strend == 0 || strend == argv[k]) { - Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "Can't understand scale specification %s", - argv[k])); + if (Tcl_GetDouble(interp, argv[k], &scale) != TCL_OK) { return TCL_ERROR; } if (scale <= 0.01 || scale >= 100.0) { -- cgit v0.12 From 3eb69aee6980150b2fabbaaab9c5bb154af74d02 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Mon, 4 Sep 2023 11:40:42 +0000 Subject: More generic error-message for TK_ARGV_INT (just as TK_ARGV_FLOAT) --- generic/tkArgv.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/generic/tkArgv.c b/generic/tkArgv.c index c9a33d8..33e7d4f 100644 --- a/generic/tkArgv.c +++ b/generic/tkArgv.c @@ -181,10 +181,6 @@ Tk_ParseArgv( goto missingArg; } if (Tcl_GetInt(interp, argv[srcIndex], (int *) infoPtr->dst) != TCL_OK) { - Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "expected %s argument for \"%s\" but got \"%s\"", - "integer", infoPtr->key, argv[srcIndex])); - Tcl_SetErrorCode(interp, "TK", "ARG", "INTEGER", curArg,NULL); return TCL_ERROR; } srcIndex++; -- cgit v0.12