@@ -193,6 +193,7 @@ bool freadCleanup(void)
193193static inline uint64_t umax (uint64_t a , uint64_t b ) { return a > b ? a : b ; }
194194static inline uint64_t umin (uint64_t a , uint64_t b ) { return a < b ? a : b ; }
195195static inline int64_t imin ( int64_t a , int64_t b ) { return a < b ? a : b ; }
196+ static inline int iminInt ( int a , int b ) { return a < b ? a : b ; }
196197
197198/** Return value of `x` clamped to the range [upper, lower] */
198199static inline int64_t clamp_i64t (int64_t x , int64_t lower , int64_t upper ) {
@@ -2238,9 +2239,9 @@ int freadMain(freadMainArgs _args) {
22382239 double thRead = 0 , thPush = 0 ; // reductions of timings within the parallel region
22392240 int max_col = 0 ;
22402241 char * typeBumpMsg = NULL ; size_t typeBumpMsgSize = 0 ;
2241- int typeCounts [NUMTYPE ]; // used for verbose output; needs populating after first read and before reread (if any) -- see later comment
2242- #define internalErrSize 1000
2243- char internalErr [ internalErrSize + 1 ] = "" ; // must be compile time size: the message is generated and we can't free before STOP
2242+ int typeCounts [NUMTYPE ]; // used for verbose output; needs populating after first read and before reread (if any) -- see later comment
2243+ char internalErr [ 256 ] = "" ; // must be compile time size: the message is generated and we can't free before STOP
2244+
22442245 int64_t DTi = 0 ; // the current row number in DT that we are writing to
22452246 const char * headPos = pos ; // the jump start corresponding to DTi
22462247 int nSwept = 0 ; // count the number of dirty jumps that were swept
@@ -2296,7 +2297,7 @@ int freadMain(freadMainArgs _args) {
22962297 nth = omp_get_num_threads ();
22972298 if (me != 0 ) {
22982299 // # nocov start
2299- snprintf (internalErr , internalErrSize , "Master thread is not thread 0 but thread %d.\n" , me ); // # notranslate
2300+ snprintf (internalErr , sizeof ( internalErr ) , "Master thread is not thread 0 but thread %d.\n" , me ); // # notranslate
23002301 stopTeam = true;
23012302 // # nocov end
23022303 }
@@ -2518,18 +2519,19 @@ int freadMain(freadMainArgs _args) {
25182519 // Can't print because we're likely not master. So accumulate message and print afterwards.
25192520 if (thisType < joldType ) { // thisType<0 (type-exception)
25202521 if (verbose ) {
2521- char temp [ 1001 ];
2522- int len = snprintf (temp , 1000 ,
2522+ char buffer [ 256 ];
2523+ int len = snprintf (buffer , sizeof ( buffer ) ,
25232524 _ ("Column %d%s%.*s%s bumped from '%s' to '%s' due to <<%.*s>> on row %" PRId64 "\n" ),
25242525 j + 1 , colNames ? " <<" : "" , colNames ? (colNames [j ].len ) : 0 , colNames ? (colNamesAnchor + colNames [j ].off ) : "" , colNames ? ">>" : "" ,
25252526 typeName [IGNORE_BUMP (joldType )], typeName [IGNORE_BUMP (thisType )],
25262527 (int )(tch - fieldStart ), fieldStart , (int64_t )(ctx .DTi + myNrow ));
2527- if (len > 1000 ) len = 1000 ;
2528- if (len > 0 ) {
2529- typeBumpMsg = realloc (typeBumpMsg , typeBumpMsgSize + len + 1 );
2530- strcpy (typeBumpMsg + typeBumpMsgSize , temp );
2531- typeBumpMsgSize += len ;
2532- }
2528+
2529+ len = iminInt (len , sizeof (buffer ));
2530+
2531+ typeBumpMsg = realloc (typeBumpMsg , typeBumpMsgSize + len + 1 );
2532+ strcpy (typeBumpMsg + typeBumpMsgSize , buffer );
2533+ typeBumpMsgSize += len ;
2534+
25332535 }
25342536 nTypeBump ++ ;
25352537 if (joldType > 0 ) nTypeBumpCols ++ ;
@@ -2570,7 +2572,7 @@ int freadMain(freadMainArgs _args) {
25702572 }
25712573 else if (headPos != thisJumpStart && nrowLimit > 0 ) { // do not care for dirty jumps since we do not read data and only want to know types
25722574 // # nocov start
2573- snprintf (internalErr , internalErrSize , "invalid head position. jump=%d, headPos=%p, thisJumpStart=%p, sof=%p" , jump , headPos , thisJumpStart , sof ); // # notranslate
2575+ snprintf (internalErr , sizeof ( internalErr ) , "invalid head position. jump=%d, headPos=%p, thisJumpStart=%p, sof=%p" , jump , headPos , thisJumpStart , sof ); // # notranslate
25742576 stopTeam = true;
25752577 // # nocov end
25762578 }
0 commit comments