From 0d8a08dbf1d766bcd778253199b782a231a202e7 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Mon, 8 May 2023 09:35:57 +0000 Subject: Proposed fix for [96551aca55]: Avoid pointer arithmetic with NULL in FOREACH_STRUCT() --- generic/tclOOInt.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/generic/tclOOInt.h b/generic/tclOOInt.h index 725c4ce..8a19f74 100644 --- a/generic/tclOOInt.h +++ b/generic/tclOOInt.h @@ -589,12 +589,12 @@ MODULE_SCOPE void TclOOSetupVariableResolver(Tcl_Namespace *nsPtr); /* * A variation where the array is an array of structs. There's no issue with * possible NULLs; every element of the array will be iterated over and the - * varable set to a pointer to each of those elements in turn. + * variable set to a pointer to each of those elements in turn. * REQUIRES DECLARATION: int i; */ #define FOREACH_STRUCT(var,ary) \ - for(i=0 ; var=&((ary).list[i]), i<(ary).num; i++) + if ((ary).num > 0) for(i=0; var=&((ary).list[i]), i<(ary).num; i++) /* * Convenience macros for iterating through hash tables. FOREACH_HASH_DECLS -- cgit v0.12 From 133b43a5217bb5e27bced051732443f474610b9c Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Mon, 8 May 2023 13:43:56 +0000 Subject: Better version, keeping the (undocumented) behavior of 'i' initialization --- generic/tclOOInt.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/generic/tclOOInt.h b/generic/tclOOInt.h index 8a19f74..0b49359 100644 --- a/generic/tclOOInt.h +++ b/generic/tclOOInt.h @@ -590,11 +590,11 @@ MODULE_SCOPE void TclOOSetupVariableResolver(Tcl_Namespace *nsPtr); * A variation where the array is an array of structs. There's no issue with * possible NULLs; every element of the array will be iterated over and the * variable set to a pointer to each of those elements in turn. - * REQUIRES DECLARATION: int i; + * REQUIRES DECLARATION: int i; See [96551aca55] for more FOREACH_STRUCT details. */ #define FOREACH_STRUCT(var,ary) \ - if ((ary).num > 0) for(i=0; var=&((ary).list[i]), i<(ary).num; i++) + i=0; if ((ary).num > 0) for(; var=&((ary).list[i]), i<(ary).num; i++) /* * Convenience macros for iterating through hash tables. FOREACH_HASH_DECLS -- cgit v0.12 From 2e02e1affdde86a1dd00fc78a73af5924c6d30a0 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Tue, 9 May 2023 13:06:02 +0000 Subject: Remove useless type-casts. Backport some changes from 9.0 --- win/tclWinFile.c | 10 +++++----- win/tclWinReg.c | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/win/tclWinFile.c b/win/tclWinFile.c index f0c46f9..adc1d7d 100644 --- a/win/tclWinFile.c +++ b/win/tclWinFile.c @@ -170,7 +170,7 @@ static int NativeWriteReparse(const WCHAR *LinkDirectory, static int NativeMatchType(int isDrive, DWORD attr, const WCHAR *nativeName, Tcl_GlobTypeData *types); static int WinIsDrive(const char *name, size_t nameLen); -static Tcl_Size WinIsReserved(const char *path); +static size_t WinIsReserved(const char *path); static Tcl_Obj * WinReadLink(const WCHAR *LinkSource); static Tcl_Obj * WinReadLinkDirectory(const WCHAR *LinkDirectory); static int WinLink(const WCHAR *LinkSource, @@ -1245,7 +1245,7 @@ WinIsDrive( * (not any trailing :). */ -static Tcl_Size +static size_t WinIsReserved( const char *path) /* Path in UTF-8 */ { @@ -2579,14 +2579,14 @@ TclpObjNormalizePath( */ if (isDrive) { - Tcl_Size len = WinIsReserved(path); + size_t len = WinIsReserved(path); if (len > 0) { /* * Actually it does exist - COM1, etc. */ - Tcl_Size i; + size_t i; for (i=0 ; i