From a3c65be91a55c8aff5884b1185ecbc9d42afb4d7 Mon Sep 17 00:00:00 2001 From: Jacob Yen Date: Fri, 30 Oct 2026 21:51:51 +0800 Subject: [PATCH] Fix ClearFlag indexing and flag-range diagnostics --- check/fixes.frm | 36 ++++++++++++++++++++++++++++++++++++ sources/compcomm.c | 6 +++--- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/check/fixes.frm b/check/fixes.frm index 94c7198c..35604af8 100644 --- a/check/fixes.frm +++ b/check/fixes.frm @@ -5613,3 +5613,39 @@ Print; assert succeeded? assert result("test") =~ expr("0") *--#] PullReq860_3 : + +*--#[ Issue855 : +L F = 1; +#do i=1,16 + #setflag `i',F +#enddo +ClearFlag 1,5,16; +.sort +#do i=1,16 + #if flag(`i',F) + #message flag(`i',F) is set + #else + #message flag(`i',F) is clear + #endif +#enddo +.end +assert succeeded? +(1..16).each do |i| + expected = [1, 5, 16].include?(i) ? "clear" : "set" + assert stdout.include?("~~~flag(#{i},F) is #{expected}") +end +*--#] Issue855 : + +*--#[ Issue855_SetFlagRange : +L F = 1; +SetFlag 0; +.end +assert compile_error?("Flag number 0 outside the permitted range 1-") +*--#] Issue855_SetFlagRange : + +*--#[ Issue855_ClearFlagRange : +L F = 1; +ClearFlag 999; +.end +assert compile_error?("Flag number 999 outside the permitted range 1-") +*--#] Issue855_ClearFlagRange : diff --git a/sources/compcomm.c b/sources/compcomm.c index 4c281613..7363a42f 100644 --- a/sources/compcomm.c +++ b/sources/compcomm.c @@ -7428,7 +7428,7 @@ int CoSetUserFlag(UBYTE *s) int x = 0; while ( *s && ( FG.cTable[*s] == 1 ) ) x = 10*x+(*s++ - '0'); if ( x < 1 || x > BITSINWORD ) { - MesPrint("&Flag number %d outside the permitted range 1-%d.",BITSINWORD); + MesPrint("&Flag number %d outside the permitted range 1-%d.",x,BITSINWORD); error = 1; } else { @@ -7456,11 +7456,11 @@ int CoClearUserFlag(UBYTE *s) int x = 0; while ( *s && ( FG.cTable[*s] == 1 ) ) x = 10*x+(*s++ - '0'); if ( x < 1 || x > BITSINWORD ) { - MesPrint("&Flag number %d outside the permitted range 1-%d.",BITSINWORD); + MesPrint("&Flag number %d outside the permitted range 1-%d.",x,BITSINWORD); error = 1; } else { - Add3Com(TYPECLEARUSERFLAG,x); + Add3Com(TYPECLEARUSERFLAG,x-1); } while ( *s && ( *s == ',' || *s == ' ' || *s == '\t' ) ) s++; }