fixed bug with parsing timezone files with a tzh_timecnt of zero
authorbeware <beware@bircd.org>
Mon, 22 Sep 2025 00:32:23 +0000 (00:32 +0000)
committerbeware <beware@bircd.org>
Mon, 22 Sep 2025 00:32:23 +0000 (00:32 +0000)
btime.pas

index ae6ffa56a72c149b5944c9feeeca3821798a22a7..4052493401c1367a5ca72afbfeb0ad334c575ce3 100644 (file)
--- a/btime.pas
+++ b/btime.pas
@@ -848,19 +848,23 @@ begin
    if (tzh_timecnt < 0) or (tzh_timecnt > fs) then raise exception.create('tzh_timecnt');\r
    ofs2 := ofs;\r
 \r
    if (tzh_timecnt < 0) or (tzh_timecnt > fs) then raise exception.create('tzh_timecnt');\r
    ofs2 := ofs;\r
 \r
-   for a := 0 to tzh_timecnt -1 do begin\r
-     if mode64 then t := getint64 else t := getint;\r
-     if (t > ts) then begin\r
-       index := a - 1;\r
-       break;\r
+   if (tzh_timecnt <> 0) then begin\r
+     for a := 0 to tzh_timecnt -1 do begin\r
+       if mode64 then t := getint64 else t := getint;\r
+       if (t > ts) then begin\r
+         index := a - 1;\r
+         break;\r
+       end;\r
+       if (a = tzh_timecnt -1) and (ts >= t) then index := a;\r
      end;\r
      end;\r
-     if (a = tzh_timecnt -1) and (ts >= t) then index := a;\r
-   end;\r
-   ofs := ofs2 + tzh_timecnt * (1 + ord(mode64)) * 4;\r
+     ofs := ofs2 + tzh_timecnt * (1 + ord(mode64)) * 4;\r
 \r
 \r
-   if (cardinal(ofs + index) >= fs) or (index < 0) then raise exception.create('index');\r
-   index := buf[ofs+index];\r
-   inc(ofs,tzh_timecnt);\r
+     if (cardinal(ofs + index) >= fs) or (index < 0) then raise exception.create('index');\r
+     index := buf[ofs+index];\r
+     inc(ofs,tzh_timecnt);\r
+   end else begin\r
+     index := 0;\r
+   end;\r
 \r
    if (index >= tzh_typecnt) then raise exception.create('type');\r
    ofs2 := ofs;\r
 \r
    if (index >= tzh_typecnt) then raise exception.create('type');\r
    ofs2 := ofs;\r