Fossil SCM

In thEvalLocal(), do not read the byte after the end of a script. When the last command of a script ran to its end, or the script ended with a semicolon, one more byte was examined; for the body of a TH1 procedure without parameters that byte is past the end of its allocation.

dmestas 2026-11-16 18:02 UTC small-fixes-2
Commit 856b85ede27ef1a77f0fbbd6d51c21999503f02b29f7ec4e7aba2bab23e17612
1 file changed +2 -2
+2 -2
--- src/th.c
+++ src/th.c
@@ -947,11 +947,11 @@
947947
zInput += nSpace;
948948
nInput -= nSpace;
949949
zFirst = zInput;
950950
951951
/* Check for a comment. If found, skip to the end of the line. */
952
- if( zInput[0]=='#' ){
952
+ if( nInput>0 && zInput[0]=='#' ){
953953
while( !thEndOfLine(zInput, nInput) ){
954954
zInput++;
955955
nInput--;
956956
}
957957
continue;
@@ -958,11 +958,11 @@
958958
}
959959
960960
/* Gobble up input a word at a time until the end of the command
961961
** (a semi-colon or end of line).
962962
*/
963
- while( rc==TH_OK && *zInput!=';' && !thEndOfLine(zInput, nInput) ){
963
+ while( rc==TH_OK && !thEndOfLine(zInput, nInput) && *zInput!=';' ){
964964
int nWord=0;
965965
thNextSpace(interp, zInput, nInput, &nSpace);
966966
rc = thNextWord(interp, &zInput[nSpace], nInput-nSpace, &nWord, 1);
967967
zInput += (nSpace+nWord);
968968
nInput -= (nSpace+nWord);
969969
--- src/th.c
+++ src/th.c
@@ -947,11 +947,11 @@
947 zInput += nSpace;
948 nInput -= nSpace;
949 zFirst = zInput;
950
951 /* Check for a comment. If found, skip to the end of the line. */
952 if( zInput[0]=='#' ){
953 while( !thEndOfLine(zInput, nInput) ){
954 zInput++;
955 nInput--;
956 }
957 continue;
@@ -958,11 +958,11 @@
958 }
959
960 /* Gobble up input a word at a time until the end of the command
961 ** (a semi-colon or end of line).
962 */
963 while( rc==TH_OK && *zInput!=';' && !thEndOfLine(zInput, nInput) ){
964 int nWord=0;
965 thNextSpace(interp, zInput, nInput, &nSpace);
966 rc = thNextWord(interp, &zInput[nSpace], nInput-nSpace, &nWord, 1);
967 zInput += (nSpace+nWord);
968 nInput -= (nSpace+nWord);
969
--- src/th.c
+++ src/th.c
@@ -947,11 +947,11 @@
947 zInput += nSpace;
948 nInput -= nSpace;
949 zFirst = zInput;
950
951 /* Check for a comment. If found, skip to the end of the line. */
952 if( nInput>0 && zInput[0]=='#' ){
953 while( !thEndOfLine(zInput, nInput) ){
954 zInput++;
955 nInput--;
956 }
957 continue;
@@ -958,11 +958,11 @@
958 }
959
960 /* Gobble up input a word at a time until the end of the command
961 ** (a semi-colon or end of line).
962 */
963 while( rc==TH_OK && !thEndOfLine(zInput, nInput) && *zInput!=';' ){
964 int nWord=0;
965 thNextSpace(interp, zInput, nInput, &nSpace);
966 rc = thNextWord(interp, &zInput[nSpace], nInput-nSpace, &nWord, 1);
967 zInput += (nSpace+nWord);
968 nInput -= (nSpace+nWord);
969

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button