From 8b0a5c9660a2bf7029a65e230ac21a03872e044a Mon Sep 17 00:00:00 2001 From: badasahog <52379863+badasahog@users.noreply.github.com> Date: Wed, 4 Jun 2025 09:55:10 -0400 Subject: [PATCH 1/8] removed macro `internalErrSize` --- src/fread.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/fread.c b/src/fread.c index 44ded6f3f0..181f28b79d 100644 --- a/src/fread.c +++ b/src/fread.c @@ -2257,8 +2257,7 @@ int freadMain(freadMainArgs _args) { int max_col=0; char *typeBumpMsg=NULL; size_t typeBumpMsgSize=0; int typeCounts[NUMTYPE]; // used for verbose output; needs populating after first read and before reread (if any) -- see later comment - #define internalErrSize 1000 - char internalErr[internalErrSize+1]=""; // must be compile time size: the message is generated and we can't free before STOP + char internalErr[1001]=""; // must be compile time size: the message is generated and we can't free before STOP int64_t DTi = 0; // the current row number in DT that we are writing to const char *headPos = pos; // the jump start corresponding to DTi int nSwept = 0; // count the number of dirty jumps that were swept @@ -2314,7 +2313,7 @@ int freadMain(freadMainArgs _args) { nth = omp_get_num_threads(); if (me!=0) { // # nocov start - snprintf(internalErr, internalErrSize, "Master thread is not thread 0 but thread %d.\n", me); // # notranslate + snprintf(internalErr, sizeof(internalErr) - 1, "Master thread is not thread 0 but thread %d.\n", me); // # notranslate stopTeam = true; // # nocov end } @@ -2583,7 +2582,7 @@ int freadMain(freadMainArgs _args) { } else if (headPos!=thisJumpStart && nrowLimit>0) { // do not care for dirty jumps since we do not read data and only want to know types // # nocov start - snprintf(internalErr, internalErrSize, "invalid head position. jump=%d, headPos=%p, thisJumpStart=%p, sof=%p", jump, headPos, thisJumpStart, sof); // # notranslate + snprintf(internalErr, sizeof(internalErr) - 1, "invalid head position. jump=%d, headPos=%p, thisJumpStart=%p, sof=%p", jump, headPos, thisJumpStart, sof); // # notranslate stopTeam = true; // # nocov end } From 358e95789c8a2bffc27f8f268200f845403ad148 Mon Sep 17 00:00:00 2001 From: badasahog <52379863+badasahog@users.noreply.github.com> Date: Sat, 7 Jun 2025 13:46:59 -0400 Subject: [PATCH 2/8] no need for `- 1` --- src/fread.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fread.c b/src/fread.c index 181f28b79d..c284569c31 100644 --- a/src/fread.c +++ b/src/fread.c @@ -2257,7 +2257,7 @@ int freadMain(freadMainArgs _args) { int max_col=0; char *typeBumpMsg=NULL; size_t typeBumpMsgSize=0; int typeCounts[NUMTYPE]; // used for verbose output; needs populating after first read and before reread (if any) -- see later comment - char internalErr[1001]=""; // must be compile time size: the message is generated and we can't free before STOP + char internalErr[256]=""; // must be compile time size: the message is generated and we can't free before STOP int64_t DTi = 0; // the current row number in DT that we are writing to const char *headPos = pos; // the jump start corresponding to DTi int nSwept = 0; // count the number of dirty jumps that were swept @@ -2313,7 +2313,7 @@ int freadMain(freadMainArgs _args) { nth = omp_get_num_threads(); if (me!=0) { // # nocov start - snprintf(internalErr, sizeof(internalErr) - 1, "Master thread is not thread 0 but thread %d.\n", me); // # notranslate + snprintf(internalErr, sizeof(internalErr), "Master thread is not thread 0 but thread %d.\n", me); // # notranslate stopTeam = true; // # nocov end } @@ -2582,7 +2582,7 @@ int freadMain(freadMainArgs _args) { } else if (headPos!=thisJumpStart && nrowLimit>0) { // do not care for dirty jumps since we do not read data and only want to know types // # nocov start - snprintf(internalErr, sizeof(internalErr) - 1, "invalid head position. jump=%d, headPos=%p, thisJumpStart=%p, sof=%p", jump, headPos, thisJumpStart, sof); // # notranslate + snprintf(internalErr, sizeof(internalErr), "invalid head position. jump=%d, headPos=%p, thisJumpStart=%p, sof=%p", jump, headPos, thisJumpStart, sof); // # notranslate stopTeam = true; // # nocov end } From 7318cc424596e784e0d61c137811544726c51dad Mon Sep 17 00:00:00 2001 From: badasahog <52379863+badasahog@users.noreply.github.com> Date: Mon, 9 Jun 2025 04:11:39 -0400 Subject: [PATCH 3/8] also fixed a different buffer --- src/fread.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/fread.c b/src/fread.c index c284569c31..eb36be6cdf 100644 --- a/src/fread.c +++ b/src/fread.c @@ -2530,18 +2530,18 @@ int freadMain(freadMainArgs _args) { // Can't print because we're likely not master. So accumulate message and print afterwards. if (thisType < joldType) { // thisType<0 (type-exception) if (verbose) { - char temp[1001]; - int len = snprintf(temp, 1000, + char buffer[250]; + int len = snprintf(buffer, sizeof(buffer), _("Column %d%s%.*s%s bumped from '%s' to '%s' due to <<%.*s>> on row %"PRId64"\n"), j+1, colNames?" <<":"", colNames?(colNames[j].len):0, colNames?(colNamesAnchor+colNames[j].off):"", colNames?">>":"", typeName[IGNORE_BUMP(joldType)], typeName[IGNORE_BUMP(thisType)], (int)(tch-fieldStart), fieldStart, (int64_t)(ctx.DTi+myNrow)); - if (len > 1000) len = 1000; - if (len > 0) { - typeBumpMsg = realloc(typeBumpMsg, typeBumpMsgSize + len + 1); - strcpy(typeBumpMsg+typeBumpMsgSize, temp); - typeBumpMsgSize += len; - } + + len = min(len, sizeof(buffer)); + + typeBumpMsg = realloc(typeBumpMsg, typeBumpMsgSize + len + 1); + strcpy(typeBumpMsg+typeBumpMsgSize, buffer); + typeBumpMsgSize += len; } nTypeBump++; if (joldType>0) nTypeBumpCols++; From bf8503a4c1e99686ee7b2df51a7033b2d92d9d04 Mon Sep 17 00:00:00 2001 From: badasahog <52379863+badasahog@users.noreply.github.com> Date: Mon, 9 Jun 2025 05:22:04 -0400 Subject: [PATCH 4/8] 256 is probably better --- src/fread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fread.c b/src/fread.c index eb36be6cdf..77f76f14a0 100644 --- a/src/fread.c +++ b/src/fread.c @@ -2530,7 +2530,7 @@ int freadMain(freadMainArgs _args) { // Can't print because we're likely not master. So accumulate message and print afterwards. if (thisType < joldType) { // thisType<0 (type-exception) if (verbose) { - char buffer[250]; + char buffer[256]; int len = snprintf(buffer, sizeof(buffer), _("Column %d%s%.*s%s bumped from '%s' to '%s' due to <<%.*s>> on row %"PRId64"\n"), j+1, colNames?" <<":"", colNames?(colNames[j].len):0, colNames?(colNamesAnchor+colNames[j].off):"", colNames?">>":"", From 2a4cbe4b95d8274de626eabebc720d1e72b560f8 Mon Sep 17 00:00:00 2001 From: badasahog <52379863+badasahog@users.noreply.github.com> Date: Mon, 16 Jun 2025 06:44:40 -0400 Subject: [PATCH 5/8] fixed mingw support --- src/fread.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fread.c b/src/fread.c index 77f76f14a0..154e07605f 100644 --- a/src/fread.c +++ b/src/fread.c @@ -190,6 +190,7 @@ bool freadCleanup(void) static inline uint64_t umax(uint64_t a, uint64_t b) { return a > b ? a : b; } static inline uint64_t umin(uint64_t a, uint64_t b) { return a < b ? a : b; } static inline int64_t imin( int64_t a, int64_t b) { return a < b ? a : b; } +static inline int iminInt( int a, int b) { return a < b ? a : b; } /** Return value of `x` clamped to the range [upper, lower] */ static inline int64_t clamp_i64t(int64_t x, int64_t lower, int64_t upper) { @@ -2537,7 +2538,7 @@ int freadMain(freadMainArgs _args) { typeName[IGNORE_BUMP(joldType)], typeName[IGNORE_BUMP(thisType)], (int)(tch-fieldStart), fieldStart, (int64_t)(ctx.DTi+myNrow)); - len = min(len, sizeof(buffer)); + len = iminInt(len, sizeof(buffer)); typeBumpMsg = realloc(typeBumpMsg, typeBumpMsgSize + len + 1); strcpy(typeBumpMsg+typeBumpMsgSize, buffer); From 899c0770e2b6a801c05ef1369c971075dd9f3af5 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Sun, 29 Jun 2025 13:50:11 -0700 Subject: [PATCH 6/8] ws --- src/fread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fread.c b/src/fread.c index 3c4c198951..88a2540e27 100644 --- a/src/fread.c +++ b/src/fread.c @@ -2238,7 +2238,7 @@ int freadMain(freadMainArgs _args) { double tRead = 0, tReread = 0; double thRead = 0, thPush = 0; // reductions of timings within the parallel region int max_col = 0; - char *typeBumpMsg = NULL; size_t typeBumpMsgSize=0; + char *typeBumpMsg = NULL; size_t typeBumpMsgSize = 0; int typeCounts[NUMTYPE]; // used for verbose output; needs populating after first read and before reread (if any) -- see later comment char internalErr[256] = ""; // must be compile time size: the message is generated and we can't free before STOP From 81aeb70d4510cc4a48ef7167f66e1b1d209887d8 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Sun, 29 Jun 2025 13:50:32 -0700 Subject: [PATCH 7/8] ws2 --- src/fread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fread.c b/src/fread.c index 88a2540e27..5de851ca63 100644 --- a/src/fread.c +++ b/src/fread.c @@ -2238,7 +2238,7 @@ int freadMain(freadMainArgs _args) { double tRead = 0, tReread = 0; double thRead = 0, thPush = 0; // reductions of timings within the parallel region int max_col = 0; - char *typeBumpMsg = NULL; size_t typeBumpMsgSize = 0; + char *typeBumpMsg = NULL; size_t typeBumpMsgSize = 0; int typeCounts[NUMTYPE]; // used for verbose output; needs populating after first read and before reread (if any) -- see later comment char internalErr[256] = ""; // must be compile time size: the message is generated and we can't free before STOP From 99b86cfcc7d059fe6fee9e769edbea255261a69a Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Sun, 29 Jun 2025 13:52:26 -0700 Subject: [PATCH 8/8] ws3 (failed merge resolution) --- src/fread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fread.c b/src/fread.c index 362135faf0..4abed040c4 100644 --- a/src/fread.c +++ b/src/fread.c @@ -2524,7 +2524,7 @@ int freadMain(freadMainArgs _args) { _("Column %d%s%.*s%s bumped from '%s' to '%s' due to <<%.*s>> on row %"PRId64"\n"), j + 1, colNames ? " <<" : "", colNames ? (colNames[j].len) : 0, colNames ? (colNamesAnchor + colNames[j].off) : "", colNames ? ">>" : "", typeName[IGNORE_BUMP(joldType)], typeName[IGNORE_BUMP(thisType)], - (int)(tch-fieldStart), fieldStart, (int64_t)(ctx.DTi + myNrow)); + (int)(tch - fieldStart), fieldStart, (int64_t)(ctx.DTi + myNrow)); len = iminInt(len, sizeof(buffer));