summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generic/tkArgv.c15
-rw-r--r--generic/tkCanvLine.c23
-rw-r--r--generic/tkCanvPoly.c14
-rw-r--r--generic/tkCanvPs.c52
-rw-r--r--generic/tkCanvText.c17
-rw-r--r--generic/tkGet.c125
-rw-r--r--generic/tkImgListFormat.c4
-rw-r--r--generic/tkListbox.c21
-rw-r--r--generic/tkMenu.c30
-rw-r--r--generic/tkObj.c65
-rw-r--r--win/tkWinGDI.c6
11 files changed, 204 insertions, 168 deletions
diff --git a/generic/tkArgv.c b/generic/tkArgv.c
index 39e8e37..33e7d4f 100644
--- a/generic/tkArgv.c
+++ b/generic/tkArgv.c
@@ -83,7 +83,6 @@ Tk_ParseArgv(
* than srcIndex). */
int argc; /* # arguments in argv still to process. */
size_t length; /* Number of characters in current argument. */
- char *endPtr; /* Used for identifying junk in arguments. */
int i;
if (flags & TK_ARGV_DONT_SKIP_FIRST_ARG) {
@@ -181,12 +180,7 @@ Tk_ParseArgv(
if (argc == 0) {
goto missingArg;
}
- *((int *) infoPtr->dst) = strtol(argv[srcIndex], &endPtr, 0);
- if ((endPtr == argv[srcIndex]) || (*endPtr != 0)) {
- 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);
+ if (Tcl_GetInt(interp, argv[srcIndex], (int *) infoPtr->dst) != TCL_OK) {
return TCL_ERROR;
}
srcIndex++;
@@ -215,12 +209,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/tkCanvPoly.c b/generic/tkCanvPoly.c
index 3469595..8c824b2 100644
--- a/generic/tkCanvPoly.c
+++ b/generic/tkCanvPoly.c
@@ -1737,17 +1737,19 @@ GetPolygonIndex(
if (string[0] == '@') {
int i;
double x, y, bestDist, dist, *coordPtr;
- char *end;
+ char *rest;
const char *p;
p = string+1;
- x = strtod(p, &end);
- if ((end == p) || (*end != ',')) {
+ rest = strchr(p, ',');
+ *rest = '\0';
+ if (Tcl_GetDouble(NULL, p, &x) != TCL_OK) {
+ *rest = ',';
goto badIndex;
}
- p = end+1;
- y = strtod(p, &end);
- if ((end == p) || (*end != 0)) {
+ *rest = ',';
+ p = rest+1;
+ if (Tcl_GetDouble(NULL, p, &y) != TCL_OK) {
goto badIndex;
}
bestDist = 1.0e36;
diff --git a/generic/tkCanvPs.c b/generic/tkCanvPs.c
index 4b63895..d9759d7 100644
--- a/generic/tkCanvPs.c
+++ b/generic/tkCanvPs.c
@@ -1104,50 +1104,54 @@ GetPostscriptPoints(
char *string, /* String describing a screen distance. */
double *doublePtr) /* Place to store converted result. */
{
- char *end;
+ const char *rest;
double d;
+ Tcl_DString ds;
- d = strtod(string, &end);
- if (end == string) {
- goto error;
+ if (Tcl_GetDouble(NULL, string, &d) == TCL_OK) {
+ *doublePtr = d;
+ return TCL_OK;
+ }
+ rest = string + strlen(string);
+ while ((rest > string) && isspace(UCHAR(rest[-1]))) {
+ --rest; /* skip all spaces at the end */
}
- while ((*end != '\0') && isspace(UCHAR(*end))) {
- end++;
+ if (rest > string) {
+ --rest; /* point to the character just before the last space */
+ }
+ if (rest == string) {
+ error:
+ if (interp != NULL) {
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "bad distance \"%s\"", string));
+ Tcl_SetErrorCode(interp, "TK", "CANVAS", "PS", "POINTS", NULL);
+ }
+ return TCL_ERROR;
+ }
+ Tcl_DStringInit(&ds);
+ Tcl_DStringAppend(&ds, string, rest-string);
+ if (Tcl_GetDouble(NULL, Tcl_DStringValue(&ds), &d) != TCL_OK) {
+ Tcl_DStringFree(&ds);
+ goto error;
}
- switch (*end) {
+ Tcl_DStringFree(&ds);
+ switch (*rest) {
case 'c':
d *= 72.0/2.54;
- end++;
break;
case 'i':
d *= 72.0;
- end++;
break;
case 'm':
d *= 72.0/25.4;
- end++;
- break;
- case 0:
break;
case 'p':
- end++;
break;
default:
goto error;
}
- while ((*end != '\0') && isspace(UCHAR(*end))) {
- end++;
- }
- if (*end != 0) {
- goto error;
- }
*doublePtr = d;
return TCL_OK;
-
- error:
- Tcl_SetObjResult(interp, Tcl_ObjPrintf("bad distance \"%s\"", string));
- Tcl_SetErrorCode(interp, "TK", "CANVAS", "PS", "POINTS", NULL);
- return TCL_ERROR;
}
/*
diff --git a/generic/tkCanvText.c b/generic/tkCanvText.c
index aaf7c14..185d4a4 100644
--- a/generic/tkCanvText.c
+++ b/generic/tkCanvText.c
@@ -1502,18 +1502,23 @@ GetTextIndex(
} else if (c == '@') {
int x, y;
double tmp, cs = textPtr->cosine, s = textPtr->sine;
- char *end;
+ char *rest;
const char *p;
p = string+1;
- tmp = strtod(p, &end);
- if ((end == p) || (*end != ',')) {
+ rest = strchr(p, ',');
+ if (!rest) {
goto badIndex;
}
+ *rest = '\0';
+ if (Tcl_GetDouble(NULL, p, &tmp) != TCL_OK) {
+ *rest = ',';
+ goto badIndex;
+ }
+ *rest = ',';
x = (int) ((tmp < 0) ? tmp - 0.5 : tmp + 0.5);
- p = end+1;
- tmp = strtod(p, &end);
- if ((end == p) || (*end != 0)) {
+ p = rest+1;
+ if (Tcl_GetDouble(NULL, p, &tmp) != TCL_OK) {
goto badIndex;
}
y = (int) ((tmp < 0) ? tmp - 0.5 : tmp + 0.5);
diff --git a/generic/tkGet.c b/generic/tkGet.c
index 2eae8eb..2b0e7ee 100644
--- a/generic/tkGet.c
+++ b/generic/tkGet.c
@@ -573,53 +573,63 @@ Tk_GetScreenMM(
const char *string, /* String describing a screen distance. */
double *doublePtr) /* Place to store converted result. */
{
- char *end;
+ const char *rest;
double d;
-
- d = strtod(string, &end);
- if (end == string) {
- goto error;
- }
- while ((*end != '\0') && isspace(UCHAR(*end))) {
- end++;
- }
- switch (*end) {
- case 0:
+ Tcl_DString ds;
+
+ if (Tcl_GetDouble(NULL, string, &d) == TCL_OK) {
+ if (!tkwin) {
+ if (interp != NULL) {
+ Tcl_SetObjResult(interp, Tcl_NewStringObj("bad screen", -1));
+ Tcl_SetErrorCode(interp, "TK", "VALUE", "SCREEN_DISTANCE", NULL);
+ }
+ return TCL_ERROR;
+ }
d /= WidthOfScreen(Tk_Screen(tkwin));
d *= WidthMMOfScreen(Tk_Screen(tkwin));
- break;
+ *doublePtr = d;
+ return TCL_OK;
+ }
+ rest = string + strlen(string);
+ while ((rest > string) && isspace(UCHAR(rest[-1]))) {
+ --rest; /* skip all spaces at the end */
+ }
+ if (rest > string) {
+ --rest; /* point to the character just before the last space */
+ }
+ if (rest == string) {
+ error:
+ if (interp != NULL) {
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "bad screen distance \"%s\"", string));
+ Tcl_SetErrorCode(interp, "TK", "VALUE", "SCREEN_DISTANCE", NULL);
+ }
+ return TCL_ERROR;
+ }
+ Tcl_DStringInit(&ds);
+ Tcl_DStringAppend(&ds, string, rest-string);
+ if (Tcl_GetDouble(NULL, Tcl_DStringValue(&ds), &d) != TCL_OK) {
+ Tcl_DStringFree(&ds);
+ goto error;
+ }
+ Tcl_DStringFree(&ds);
+ switch (*rest) {
case 'c':
d *= 10;
- end++;
break;
case 'i':
d *= 25.4;
- end++;
break;
case 'm':
- end++;
break;
case 'p':
d *= 25.4/72.0;
- end++;
break;
default:
goto error;
}
- while ((*end != '\0') && isspace(UCHAR(*end))) {
- end++;
- }
- if (*end != 0) {
- goto error;
- }
*doublePtr = d;
return TCL_OK;
-
- error:
- Tcl_SetObjResult(interp, Tcl_ObjPrintf(
- "bad screen distance \"%s\"", string));
- Tcl_SetErrorCode(interp, "TK", "VALUE", "SCREEN_DISTANCE", NULL);
- return TCL_ERROR;
}
/*
@@ -693,61 +703,66 @@ TkGetDoublePixels(
const char *string, /* String describing a number of pixels. */
double *doublePtr) /* Place to store converted result. */
{
- char *end;
+ const char *rest;
double d;
+ Tcl_DString ds;
+ if (Tcl_GetDouble(NULL, string, &d) == TCL_OK) {
+ *doublePtr = d;
+ return TCL_OK;
+ }
if (!tkwin) {
- Tcl_SetObjResult(interp, Tcl_ObjPrintf("bad screen"));
- Tcl_SetErrorCode(interp, "TK", "VALUE", "FRACTIONAL_PIXELS", NULL);
+ if (interp != NULL) {
+ Tcl_SetObjResult(interp, Tcl_NewStringObj("bad screen", -1));
+ Tcl_SetErrorCode(interp, "TK", "VALUE", "FRACTIONAL_PIXELS", NULL);
+ }
return TCL_ERROR;
}
- d = strtod((char *) string, &end);
- if (end == string) {
- goto error;
+ rest = string + strlen(string);
+ while ((rest > string) && isspace(UCHAR(rest[-1]))) {
+ --rest; /* skip all spaces at the end */
}
- while ((*end != '\0') && isspace(UCHAR(*end))) {
- end++;
+ if (rest > string) {
+ --rest; /* point to the character just before the last space */
}
- switch (*end) {
- case 0:
- break;
+ if (rest == string) {
+ error:
+ if (interp != NULL) {
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "bad screen distance \"%s\"", string));
+ Tcl_SetErrorCode(interp, "TK", "VALUE", "FRACTIONAL_PIXELS", NULL);
+ }
+ return TCL_ERROR;
+ }
+ Tcl_DStringInit(&ds);
+ Tcl_DStringAppend(&ds, string, rest-string);
+ if (Tcl_GetDouble(NULL, Tcl_DStringValue(&ds), &d) != TCL_OK) {
+ Tcl_DStringFree(&ds);
+ goto error;
+ }
+ Tcl_DStringFree(&ds);
+ switch (*rest) {
case 'c':
d *= 10*WidthOfScreen(Tk_Screen(tkwin));
d /= WidthMMOfScreen(Tk_Screen(tkwin));
- end++;
break;
case 'i':
d *= 25.4*WidthOfScreen(Tk_Screen(tkwin));
d /= WidthMMOfScreen(Tk_Screen(tkwin));
- end++;
break;
case 'm':
d *= WidthOfScreen(Tk_Screen(tkwin));
d /= WidthMMOfScreen(Tk_Screen(tkwin));
- end++;
break;
case 'p':
d *= (25.4/72.0)*WidthOfScreen(Tk_Screen(tkwin));
d /= WidthMMOfScreen(Tk_Screen(tkwin));
- end++;
break;
default:
goto error;
}
- while ((*end != '\0') && isspace(UCHAR(*end))) {
- end++;
- }
- if (*end != 0) {
- goto error;
- }
*doublePtr = d;
return TCL_OK;
-
- error:
- Tcl_SetObjResult(interp, Tcl_ObjPrintf(
- "bad screen distance \"%s\"", string));
- Tcl_SetErrorCode(interp, "TK", "VALUE", "FRACTIONAL_PIXELS", NULL);
- return TCL_ERROR;
}
/*
diff --git a/generic/tkImgListFormat.c b/generic/tkImgListFormat.c
index f2bd891..3601da7 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/generic/tkListbox.c b/generic/tkListbox.c
index f66c1b3..6920f3a 100644
--- a/generic/tkListbox.c
+++ b/generic/tkListbox.c
@@ -2728,7 +2728,7 @@ GetListboxIndex(
{
int result, index;
Tcl_Size idx;
- const char *stringRep;
+ char *stringRep;
result = TkGetIntForIndex(indexObj, listPtr->nElements - 1, lastOK, &idx);
if (result == TCL_OK) {
@@ -2770,17 +2770,22 @@ GetListboxIndex(
*/
int y;
- const char *start;
- char *end;
+ char *start;
+ char *rest;
start = stringRep + 1;
- y = strtol(start, &end, 0);
- if ((start == end) || (*end != ',')) {
+ rest = strchr(start, ',');
+ if (!rest) {
+ goto badIndex;
+ }
+ *rest = '\0';
+ if (Tcl_GetInt(NULL, start, &y) != TCL_OK) {
+ *rest = ',';
goto badIndex;
}
- start = end+1;
- y = strtol(start, &end, 0);
- if ((start == end) || (*end != '\0')) {
+ *rest = ',';
+ start = rest+1;
+ if (Tcl_GetInt(NULL, start, &y) != TCL_OK) {
goto badIndex;
}
*indexPtr = NearestListboxElement(listPtr, y);
diff --git a/generic/tkMenu.c b/generic/tkMenu.c
index eb62e93..a16c6c4 100644
--- a/generic/tkMenu.c
+++ b/generic/tkMenu.c
@@ -3033,30 +3033,30 @@ GetIndexFromCoords(
{
int x, y, i;
const char *p;
- char *end;
+ const char *rest;
int x2, borderwidth, max;
TkRecomputeMenu(menuPtr);
p = string + 1;
- y = strtol(p, &end, 0);
- if (end == p) {
- goto error;
- }
- Tk_GetPixelsFromObj(interp, menuPtr->tkwin,
- menuPtr->borderWidthPtr, &borderwidth);
- if (*end == ',') {
- x = y;
- p = end + 1;
- y = strtol(p, &end, 0);
- if ((end == p) || (*end != '\0')) {
+ Tk_GetPixelsFromObj(NULL, menuPtr->tkwin,
+ menuPtr->borderWidthPtr, &borderwidth);
+ rest = strchr(p, ',');
+ if (rest) {
+ Tcl_DString ds;
+ Tcl_DStringInit(&ds);
+ Tcl_DStringAppend(&ds, p, rest - p);
+
+ if (Tcl_GetInt(NULL, Tcl_DStringValue(&ds), &x) != TCL_OK) {
goto error;
}
} else {
- if (*end != '\0') {
- goto error;
- }
x = borderwidth;
+ rest = string;
}
+ p = rest + 1;
+ if (Tcl_GetInt(NULL, p, &y) != TCL_OK) {
+ goto error;
+ }
*indexPtr = -1;
diff --git a/generic/tkObj.c b/generic/tkObj.c
index 0338f6d..8978886 100644
--- a/generic/tkObj.c
+++ b/generic/tkObj.c
@@ -512,7 +512,7 @@ SetPixelFromAny(
{
ThreadSpecificData *typeCache = GetTypeCache();
const Tcl_ObjType *typePtr;
- const char *string;
+ char *string;
char *rest;
double d;
int i, units;
@@ -532,20 +532,27 @@ SetPixelFromAny(
} else if (Tcl_GetDoubleFromObj(NULL, objPtr, &d) == TCL_OK) {
units = -1;
} else {
+ char savechar;
string = Tcl_GetString(objPtr);
- d = strtod(string, &rest);
- if (rest == string) {
- goto error;
+ rest = string + strlen(string);
+ while ((rest > string) && isspace(UCHAR(rest[-1]))) {
+ --rest; /* skip all spaces at the end */
}
- while ((*rest != '\0') && isspace(UCHAR(*rest))) {
- rest++;
+ if (rest > string) {
+ --rest; /* point to the character just before the last space */
+ }
+ if (rest == string) {
+ error:
+ if (interp != NULL) {
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "bad screen distance \"%.50s\"", string));
+ Tcl_SetErrorCode(interp, "TK", "VALUE", "PIXELS", NULL);
+ }
+ return TCL_ERROR;
}
switch (*rest) {
- case '\0':
- units = -1;
- break;
case 'm':
units = 0;
break;
@@ -561,7 +568,15 @@ SetPixelFromAny(
default:
goto error;
}
+ savechar = *rest;
+ *rest = '\0';
+ if (Tcl_GetDouble(NULL, string, &d) != TCL_OK) {
+ *rest = savechar;
+ goto error;
+ }
+ *rest = savechar;
}
+
/*
* Free the old internalRep before setting the new one.
*/
@@ -586,14 +601,6 @@ SetPixelFromAny(
SET_COMPLEXPIXEL(objPtr, pixelPtr);
}
return TCL_OK;
-
- error:
- if (interp != NULL) {
- Tcl_SetObjResult(interp, Tcl_ObjPrintf(
- "bad screen distance \"%.50s\"", string));
- Tcl_SetErrorCode(interp, "TK", "VALUE", "PIXELS", NULL);
- }
- return TCL_ERROR;
}
/*
@@ -805,13 +812,21 @@ SetMMFromAny(
} else if (Tcl_GetDoubleFromObj(NULL, objPtr, &d) == TCL_OK) {
units = -1;
} else {
+ char savechar;
+
/*
* It wasn't a known int or double, so parse it.
*/
string = Tcl_GetString(objPtr);
- d = strtod(string, &rest);
+ rest = string + strlen(string);
+ while ((rest > string) && isspace(UCHAR(rest[-1]))) {
+ --rest; /* skip all spaces at the end */
+ }
+ if (rest > string) {
+ --rest; /* point to the character just before the last space */
+ }
if (rest == string) {
error:
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
@@ -819,14 +834,7 @@ SetMMFromAny(
Tcl_SetErrorCode(interp, "TK", "VALUE", "DISTANCE", NULL);
return TCL_ERROR;
}
- while ((*rest != '\0') && isspace(UCHAR(*rest))) {
- rest++;
- }
-
switch (*rest) {
- case '\0':
- units = -1;
- break;
case 'c':
units = 0;
break;
@@ -842,6 +850,13 @@ SetMMFromAny(
default:
goto error;
}
+ savechar = *rest;
+ *rest = '\0';
+ if (Tcl_GetDouble(NULL, string, &d) != TCL_OK) {
+ *rest = savechar;
+ goto error;
+ }
+ *rest = savechar;
}
/*
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) {