From 2bd0f725aab5c91f86af714a0025410e4ad0f525 Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Tue, 9 May 2023 16:28:11 +0200 Subject: [PATCH] Fix off-by-one in size of transform messages array. --- src/bin/pgcopydb/ld_transform.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/bin/pgcopydb/ld_transform.c b/src/bin/pgcopydb/ld_transform.c index 1703a3598..d9feb0774 100644 --- a/src/bin/pgcopydb/ld_transform.c +++ b/src/bin/pgcopydb/ld_transform.c @@ -652,8 +652,16 @@ stream_transform_file(char *jsonfilename, char *sqlfilename) return false; } - /* {action: B} {action: C} {action: K} {action: X} */ - int maxMesgCount = content.count; + /* + * Message are like: + * + * {action: B} {action: C} {action: K} {action: X} + * + * And when we read a COMMIT message (or KEEPALIVE or SWITCH) we prepare + * for the next message already, which means we need one more entry in the + * array than the number of lines read in the JSON file. + */ + int maxMesgCount = content.count + 1; LogicalMessageArray mesgs = { 0 }; /* the actual count is maintained in the for loop below */