Skip to content

Commit 9f38cb3

Browse files
author
jan.nijtmans
committed
Fix [a9929f112a]: Bugs in the implementation of TIP 577 ("Enhanced index values for Tk").
Remove compat/stdint.h, since stdint.h is available in all modern C compilers
2 parents 7cd1a26 + 241ca24 commit 9f38cb3

14 files changed

+19
-960
lines changed

compat/stdint.h

-919
This file was deleted.

generic/tk.h

+2
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ typedef const char *Tk_Uid;
149149

150150
#if (TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION == 6)
151151
# define Tcl_Size int
152+
# define TCL_SIZE_MAX INT_MAX
153+
# define TCL_SIZE_MODIFIER ""
152154
#endif
153155

154156
/*

generic/tkCanvText.c

+4-6
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,11 @@ UnderlineParseProc(
120120
obj.bytes = (char *)value;
121121
obj.length = strlen(value);
122122
obj.typePtr = NULL;
123-
code = TkGetIntForIndex(&obj, TCL_INDEX_END, 0, &underline);
123+
code = TkGetIntForIndex(&obj, TCL_INDEX_NONE, 0, &underline);
124124
if (code == TCL_OK) {
125-
if (underline < 0) {
126-
underline = (Tcl_Size)INT_MIN;
127-
} else if ((size_t)underline > (size_t)TCL_INDEX_END>>1) {
128-
underline++;
129-
} else if (underline >= INT_MAX) {
125+
if (underline < INT_MIN) {
126+
underline = INT_MIN;
127+
} else if (underline > INT_MAX) {
130128
underline = INT_MAX;
131129
}
132130
*underlinePtr = (int)underline;

generic/tkConfig.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -683,17 +683,17 @@ DoObjConfig(
683683
case TK_OPTION_INDEX: {
684684
Tcl_Size newIndex;
685685

686-
if (TkGetIntForIndex(valuePtr, TCL_INDEX_END, 0, &newIndex) != TCL_OK) {
686+
if (TkGetIntForIndex(valuePtr, TCL_INDEX_NONE, 0, &newIndex) != TCL_OK) {
687687
if (interp) {
688688
Tcl_AppendResult(interp, "bad index \"", Tcl_GetString(valuePtr),
689689
"\": must be integer?[+-]integer?, end?[+-]integer?, or \"\"", NULL);
690690
}
691691
return TCL_ERROR;
692692
}
693-
if (newIndex < 0) {
693+
if (newIndex < INT_MIN) {
694694
newIndex = INT_MIN;
695-
} else if ((size_t)newIndex > (size_t)TCL_INDEX_END>>1) {
696-
newIndex++;
695+
} else if (newIndex > INT_MAX) {
696+
newIndex = INT_MAX;
697697
}
698698
if (internalPtr != NULL) {
699699
*((int *) oldInternalPtr) = *((int *) internalPtr);

generic/tkIcu.c

-7
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@
1111
*/
1212

1313
#include "tkInt.h"
14-
#ifdef HAVE_STDLIB_H
15-
#include <stdlib.h>
16-
#endif
17-
18-
#ifdef HAVE_STDINT_H
19-
#include <stdint.h>
20-
#endif
2114

2215
/*
2316
* Runtime linking of libicu.

generic/tkInt.h

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#ifdef HAVE_SYS_PARAM_H
3232
# include <sys/param.h>
3333
#endif
34+
#include <stdint.h>
35+
#include <stdlib.h>
3436
#ifdef BYTE_ORDER
3537
# ifdef BIG_ENDIAN
3638
# if BYTE_ORDER == BIG_ENDIAN

generic/tkObj.c

+1-8
Original file line numberDiff line numberDiff line change
@@ -241,18 +241,11 @@ TkGetIntForIndex(
241241
const char *value = Tcl_GetString(indexObj);
242242
if (!*value) {
243243
/* empty string */
244-
*indexPtr = TCL_INDEX_NONE;
244+
*indexPtr = (end == -1) ? -1 - TCL_SIZE_MAX : TCL_INDEX_NONE;
245245
return TCL_OK;
246246
}
247247
return TCL_ERROR;
248248
}
249-
if (*indexPtr < -1) {
250-
*indexPtr = TCL_INDEX_NONE;
251-
} else if (end >= -1) {
252-
if (*indexPtr > end) {
253-
*indexPtr = end + 1;
254-
}
255-
}
256249
return TCL_OK;
257250
}
258251

generic/ttk/ttkLabel.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,12 @@ static void TextDraw(TextElement *text, Tk_Window tkwin, Drawable d, Ttk_Box b)
175175
text->textLayout, b.x, b.y, 0/*firstChar*/, -1/*lastChar*/);
176176

177177
if (text->underlineObj != NULL) {
178-
TkGetIntForIndex(text->underlineObj, TCL_INDEX_END, 0, &underline);
178+
TkGetIntForIndex(text->underlineObj, TCL_INDEX_NONE, 0, &underline);
179179
if (underline >= 0) {
180-
if ((size_t)underline > (size_t)TCL_INDEX_END>>1) {
181-
underline++;
180+
if (underline < INT_MIN) {
181+
underline = INT_MIN;
182+
} else if (underline > INT_MAX) {
183+
underline = INT_MAX;
182184
}
183185
if (text->embossed) {
184186
Tk_UnderlineTextLayout(Tk_Display(tkwin), d, gc2,

macosx/tkMacOSXPort.h

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <math.h>
2626
#include <string.h>
2727
#include <limits.h>
28-
#include <stdlib.h>
2928
#include <sys/types.h>
3029
#include <sys/file.h>
3130
#ifdef HAVE_SYS_SELECT_H

unix/Makefile.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -1745,7 +1745,7 @@ dist: $(UNIX_DIR)/configure $(UNIX_DIR)/tkConfig.h.in $(UNIX_DIR)/tk.pc.in $(MAC
17451745
$(MAC_OSX_DIR)/Tk.xcodeproj/default.pbxuser \
17461746
$(DISTDIR)/macosx/Tk.xcodeproj
17471747
$(INSTALL_DATA_DIR) $(DISTDIR)/compat
1748-
$(DIST_INSTALL_DATA) $(TOP_DIR)/license.terms $(TOP_DIR)/compat/stdint.h \
1748+
$(DIST_INSTALL_DATA) $(TOP_DIR)/license.terms \
17491749
$(TOP_DIR)/compat/stdbool.h $(DISTDIR)/compat
17501750
$(INSTALL_DATA_DIR) $(DISTDIR)/xlib
17511751
$(DIST_INSTALL_DATA) $(XLIB_DIR)/*.[ch] $(DISTDIR)/xlib

unix/tkUnixPort.h

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include <math.h>
2727
#include <string.h>
2828
#include <limits.h>
29-
#include <stdlib.h>
3029
#include <sys/types.h>
3130
#include <sys/file.h>
3231
#ifdef HAVE_SYS_SELECT_H

win/tkWinGDI.c

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515

1616
#include <windows.h>
17-
#include <stdlib.h>
1817
#include <math.h>
1918
#include <wtypes.h>
2019
#include <winspool.h>

win/tkWinPort.h

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include <stdio.h>
2525
#include <wchar.h>
2626
#include <io.h>
27-
#include <stdlib.h>
2827
#include <assert.h>
2928
#include <errno.h>
3029
#include <fcntl.h>

win/tkWinSysTray.c

-8
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,6 @@
3333

3434
#define GETHINSTANCE Tk_GetHINSTANCE()
3535

36-
#ifdef HAVE_STDLIB_H
37-
#include <stdlib.h>
38-
#endif
39-
40-
#ifdef HAVE_STDINT_H
41-
#include <stdint.h>
42-
#endif
43-
4436
typedef struct IcoInfo {
4537
HICON hIcon; /* icon handle returned by LoadIcon. */
4638
unsigned id; /* Identifier for command; used to

0 commit comments

Comments
 (0)