File 1282-Add-test-for-chunk_step-crash-after-decreasing-log-s.patch of Package erlang

From 70b0f36d5df1ece33cd068416766f220b9d69208 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?L=C3=BD=20Nh=E1=BA=ADt=20T=C3=A2m?= <lynhattam113@gmail.com>
Date: Fri, 25 Apr 2025 13:50:23 +0200
Subject: [PATCH 2/4] Add test for chunk_step crash after decreasing log size

---
 lib/kernel/test/disk_log_SUITE.erl | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/lib/kernel/test/disk_log_SUITE.erl b/lib/kernel/test/disk_log_SUITE.erl
index 2be791a571..2859bb1569 100644
--- a/lib/kernel/test/disk_log_SUITE.erl
+++ b/lib/kernel/test/disk_log_SUITE.erl
@@ -85,7 +85,9 @@
 
 	 change_attribute/1,
 
-         otp_6278/1, otp_10131/1, otp_16768/1, otp_16809/1]).
+         otp_6278/1, otp_10131/1, otp_16768/1, otp_16809/1,
+        
+         decrease_size_with_chunk_step/1]).
 
 -export([head_fun/1, hf/0, lserv/1, 
 	 measure/0, init_m/1, xx/0]).
@@ -159,7 +161,7 @@ groups() ->
      {change_size, [],
       [change_size_before, change_size_during,
        change_size_after, default_size, change_size2,
-       change_size_truncate]}].
+       change_size_truncate, decrease_size_with_chunk_step]}].
 
 init_per_suite(Config) ->
     Config.
@@ -4203,6 +4205,28 @@ otp_16809(Conf) when is_list(Conf) ->
     HeadFunc2 = info(Log, head, undef),
     ok = disk_log:close(Log).
 
+decrease_size_with_chunk_step(Conf) when is_list(Conf) ->
+    Dir = ?privdir(Conf),
+    Log = test,
+    File = filename:join(Dir, lists:concat([Log, ".LOG"])),
+    {ok, test} = disk_log:open([{size, {1000, 3}}, {name,Log},{type, wrap},
+                                {file, File}, {notify, true}]),
+    eof = disk_log:chunk(Log,start,1),
+    {error, end_of_log} = disk_log:chunk_step(Log,start,1),
+    [disk_log:log(Log, X) || X <- lists:seq(1, 1000)],
+    ok = disk_log:close(Log),
+    {ok, test} = disk_log:open([{name, Log}, {type, wrap}, {file, File},
+                                {notify, true}]),
+    %% Decrease maximum number of files from 10 to 2.
+    ok = disk_log:change_size(Log, {1000, 2}),
+    %% The exception error of rem/2 operator should not occur in here.
+    {ok, _} = disk_log:chunk_step(Log, start, 1),
+    %% Continue to append the items to the log in order to make sure it can work
+    %% as normal.
+    [disk_log:log(Log, X) || X <- lists:seq(1, 5000)],
+    ok = disk_log:close(Log),
+    del(File, 2).
+
 mark(FileName, What) ->
     {ok,Fd} = file:open(FileName, [raw, binary, read, write]),
     {ok,_} = file:position(Fd, 4),
-- 
2.43.0

openSUSE Build Service is sponsored by