@@ -637,8 +637,8 @@ void fwriteMain(fwriteMainArgs args)
637637 // Aside: codacy wants strnlen but strnlen is not in C99 (neither is strlen_s). To pass `gcc -std=c99 -Wall -pedantic`
638638 // we'd need `#define _POSIX_C_SOURCE 200809L` before #include <string.h> but that seems a step too far
639639 // and platform specific. We prefer to be pure C99.
640- if (eolLen <= 0 )
641- STOP (_ ("eol must be 1 or more bytes (usually either \\n or \\r\\n) but is length %d" ), eolLen );
640+ if (eolLen <= 0 ) // #nocov
641+ STOP (_ ("eol must be 1 or more bytes (usually either \\n or \\r\\n) but is length %d" ), eolLen ); // #nocov
642642
643643 if (verbose ) {
644644 DTPRINT (_ ("Column writers: " ));
@@ -693,6 +693,7 @@ void fwriteMain(fwriteMainArgs args)
693693 if (args .whichFun [j ] == WF_Float64 && args .scipen > 0 )
694694 // clamp width to IEEE754 max to avoid scipen=99999 allocating buffer larger than can ever be written
695695 width += (args .scipen < 350 ) ? args .scipen : 350 ;
696+ // ensure that NA string can be written
696697 if (width < naLen )
697698 width = naLen ;
698699 maxLineLen += width * 2 ; // *2 in case the longest string is all quotes and they all need to be escaped
@@ -749,21 +750,21 @@ void fwriteMain(fwriteMainArgs args)
749750 int nth = args .nth ;
750751
751752 // Calc buffSize
752- if (args .buffMB < 1 || args .buffMB > 1024 )
753- STOP (_ ("buffMB = %d is outside range 1..1024, exiting" ), args .buffMB );
754753 size_t buffSize = args .buffMB * MEGA ;
755754
756755 // Decide buffer size and rowsPerBatch for each thread
757756 // Once rowsPerBatch is decided it can't be changed
758757
759- // if maxLineLen is greater than buffize, increase buffSize
758+ // # nocov start
759+ // if maxLineLen is greater than buffSize, increase buffSize
760760 if (buffSize < maxLineLen ) {
761761 buffSize = maxLineLen ;
762762 }
763763 // ensure buffer can take header line
764764 if (nth * buffSize < headerLen ) {
765765 buffSize = headerLen / nth + 1 ;
766766 }
767+ // # nocov end
767768
768769 int rowsPerBatch = buffSize / maxLineLen ;
769770 // + 1 because of the last incomplete loop
@@ -810,17 +811,17 @@ void fwriteMain(fwriteMainArgs args)
810811 if (verbose ) {
811812 DTPRINT (_ ("Allocate %zu bytes for thread_streams\n" ), nth * sizeof (z_stream ));
812813 }
813- if (!thread_streams )
814- STOP (_ ("Failed to allocated %d bytes for threads_streams." ), (int )(nth * sizeof (z_stream )));
814+ if (!thread_streams ) // #nocov
815+ STOP (_ ("Failed to allocated %d bytes for threads_streams." ), (int )(nth * sizeof (z_stream ))); // #nocov
815816 // VLA on stack should be fine for nth structs; in zlib v1.2.11 sizeof(struct)==112 on 64bit
816817 // not declared inside the parallel region because solaris appears to move the struct in
817818 // memory when the #pragma omp for is entered, which causes zlib's internal self reference
818819 // pointer to mismatch, #4099
819820
820821 // compute zbuffSize which is the same for each thread
821822 z_stream * stream = thread_streams ;
822- if (init_stream (stream ) != Z_OK )
823- STOP (_ ("Can't init stream structure for deflateBound" ));
823+ if (init_stream (stream ) != Z_OK ) // #nocov
824+ STOP (_ ("Can't init stream structure for deflateBound" )); // #nocov
824825 zbuffSize = deflateBound (stream , buffSize );
825826 if (verbose )
826827 DTPRINT (_ ("zbuffSize=%d returned from deflateBound\n" ), (int )zbuffSize );
@@ -886,8 +887,8 @@ void fwriteMain(fwriteMainArgs args)
886887 if (args .is_gzip ) {
887888#ifndef NOZLIB
888889 z_stream * stream = thread_streams ;
889- if (init_stream (stream ) != Z_OK )
890- STOP (_ ("Can't init stream structure for writing header" ));
890+ if (init_stream (stream ) != Z_OK ) // #nocov
891+ STOP (_ ("Can't init stream structure for writing header" )); // #nocov
891892 char * zbuff = zbuffPool ;
892893 // write minimal gzip header
893894 char * header = "\037\213\10\0\0\0\0\0\0\3" ;
@@ -920,13 +921,17 @@ void fwriteMain(fwriteMainArgs args)
920921 }
921922 if (verbose )
922923 DTPRINT (_ ("Initialization done in %.3fs\n" ), 1.0 * (wallclock ()- t0 ));
924+
925+ // empty file is test in fwrite.R
926+ // # nocov start
923927 if (args .nrow == 0 ) {
924928 if (verbose )
925929 DTPRINT (_ ("No data rows present (nrow==0)\n" ));
926930 if (f != -1 && CLOSE (f ))
927931 STOP (_ ("%s: '%s'" ), strerror (errno ), args .filename );
928932 return ;
929933 }
934+ // # nocov end
930935
931936 // Write rows ----
932937
@@ -1088,8 +1093,8 @@ void fwriteMain(fwriteMainArgs args)
10881093 PUT4 (tail + 6 , len );
10891094 int ret = WRITE (f , tail , 10 );
10901095 compress_len += 10 ;
1091- if (ret == -1 )
1092- STOP ("Error: can't write gzip tailer" );
1096+ if (ret == -1 ) // #nocov
1097+ STOP ("Error: can't write gzip tailer" ); // #nocov
10931098#endif
10941099 }
10951100
0 commit comments