Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strncpy warnings #151

Closed
hadley opened this issue Oct 8, 2018 · 24 comments
Closed

strncpy warnings #151

hadley opened this issue Oct 8, 2018 · 24 comments

Comments

@hadley
Copy link
Contributor

hadley commented Oct 8, 2018

  readstat/readstat_writer.c:82:9: warning: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation]
  readstat/readstat_writer.c:261:5: warning: ‘strncpy’ specified bound 256 equals destination size [-Wstringop-truncation]
  readstat/readstat_writer.c:316:9: warning: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation]
  readstat/sas/readstat_sas7bcat_write.c:108:5: warning: ‘strncpy’ output may be truncated copying 64 bytes from a string of length 99 [-Wstringop-truncation]
  readstat/sas/readstat_sas.c:284:5: warning: ‘strncpy’ output may be truncated copying 64 bytes from a string of length 99 [-Wstringop-truncation]
  readstat/sas/readstat_sas.c:337:5: warning: ‘strncpy’ output may be truncated copying 8 bytes from a string of length 31 [-Wstringop-truncation]
  readstat/spss/readstat_sav_write.c:150:5: warning: ‘strncpy’ output may be truncated copying 9 bytes from a string of length 9 [-Wstringop-truncation]
  readstat/spss/readstat_sav_write.c:158:5: warning: ‘strncpy’ output may be truncated copying 8 bytes from a string of length 8 [-Wstringop-truncation]
  readstat/spss/readstat_por_write.c:194:5: warning: ‘strncpy’ output truncated before terminating nul copying 20 bytes from a string of the same length [-Wstringop-truncation]
@evanmiller
Copy link
Contributor

Please include compiler version and full output from ./configure etc

@hadley
Copy link
Contributor Author

hadley commented Oct 12, 2018

Full R CMD check report at https://win-builder.r-project.org/incoming_pretest/haven_2.0.0_20181009_004546/Debian/00check.log — I'll try and figure out how to get the other info

@hadley
Copy link
Contributor Author

hadley commented Oct 12, 2018

Oh duh, from simple URL manipulation:

gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c tagged_na.c -o tagged_na.o
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/readstat_parser.c -o readstat/readstat_parser.o
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/readstat_metadata.c -o readstat/readstat_metadata.o
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/readstat_io_unistd.c -o readstat/readstat_io_unistd.o
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/readstat_bits.c -o readstat/readstat_bits.o
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/readstat_variable.c -o readstat/readstat_variable.o
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/readstat_writer.c -o readstat/readstat_writer.o
In function ‘readstat_copy_label.isra.0’,
    inlined from ‘readstat_add_value_label’ at readstat/readstat_writer.c:94:5:
readstat/readstat_writer.c:82:9: warning: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation]
         strncpy(value_label->label, label, value_label->label_len);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
readstat/readstat_writer.c: In function ‘readstat_add_value_label’:
readstat/readstat_writer.c:80:34: note: length computed here
         value_label->label_len = strlen(label);
                                  ^~~~~~~~~~~~~
readstat/readstat_writer.c: In function ‘readstat_add_label_set’:
readstat/readstat_writer.c:261:5: warning: ‘strncpy’ specified bound 256 equals destination size [-Wstringop-truncation]
     strncpy(new_label_set->name, name, sizeof(new_label_set->name));
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
readstat/readstat_writer.c: In function ‘readstat_label_string_value’:
readstat/readstat_writer.c:316:9: warning: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation]
         strncpy(new_value_label->string_key, value, new_value_label->string_key_len);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
readstat/readstat_writer.c:314:43: note: length computed here
         new_value_label->string_key_len = strlen(value);
                                           ^~~~~~~~~~~~~
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/readstat_error.c -o readstat/readstat_error.o
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/readstat_convert.c -o readstat/readstat_convert.o
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/CKHashTable.c -o readstat/CKHashTable.o
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/readstat_malloc.c -o readstat/readstat_malloc.o
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/readstat_value.c -o readstat/readstat_value.o
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/sas/readstat_xport_write.c -o readstat/sas/readstat_xport_write.o
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/sas/readstat_sas7bcat_read.c -o readstat/sas/readstat_sas7bcat_read.o
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/sas/readstat_sas7bdat_write.c -o readstat/sas/readstat_sas7bdat_write.o
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/sas/readstat_sas7bcat_write.c -o readstat/sas/readstat_sas7bcat_write.o
In function ‘sas7bcat_emit_header.constprop’,
    inlined from ‘sas7bcat_begin_data’ at readstat/sas/readstat_sas7bcat_write.c:129:14:
readstat/sas/readstat_sas7bcat_write.c:108:5: warning: ‘strncpy’ output may be truncated copying 64 bytes from a string of length 99 [-Wstringop-truncation]
     strncpy(header_start.file_label, writer->file_label, sizeof(header_start.file_label));
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/sas/ieee.c -o readstat/sas/ieee.o
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/sas/readstat_xport_read.c -o readstat/sas/readstat_xport_read.o
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/sas/readstat_sas.c -o readstat/sas/readstat_sas.o
readstat/sas/readstat_sas.c: In function ‘sas_write_header’:
readstat/sas/readstat_sas.c:284:5: warning: ‘strncpy’ output may be truncated copying 64 bytes from a string of length 99 [-Wstringop-truncation]
     strncpy(header_start.file_label, writer->file_label, sizeof(header_start.file_label));
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
readstat/sas/readstat_sas.c:337:5: warning: ‘strncpy’ output may be truncated copying 8 bytes from a string of length 31 [-Wstringop-truncation]
     strncpy(header_end.release, release, sizeof(header_end.release));
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/sas/readstat_sas_rle.c -o readstat/sas/readstat_sas_rle.o
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/sas/readstat_xport.c -o readstat/sas/readstat_xport.o
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/sas/readstat_sas7bdat_read.c -o readstat/sas/readstat_sas7bdat_read.o
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/spss/readstat_sav_compress.c -o readstat/spss/readstat_sav_compress.o
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/spss/readstat_spss_parse.c -o readstat/spss/readstat_spss_parse.o
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/spss/readstat_sav_read.c -o readstat/spss/readstat_sav_read.o
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/spss/readstat_por_read.c -o readstat/spss/readstat_por_read.o
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/spss/readstat_sav.c -o readstat/spss/readstat_sav.o
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/spss/readstat_por.c -o readstat/spss/readstat_por.o
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/spss/readstat_sav_parse_timestamp.c -o readstat/spss/readstat_sav_parse_timestamp.o
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/spss/readstat_zsav_read.c -o readstat/spss/readstat_zsav_read.o
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/spss/readstat_sav_write.c -o readstat/spss/readstat_sav_write.o
readstat/spss/readstat_sav_write.c: In function ‘sav_emit_header’:
readstat/spss/readstat_sav_write.c:150:5: warning: ‘strncpy’ output may be truncated copying 9 bytes from a string of length 9 [-Wstringop-truncation]
     strncpy(header.creation_date, creation_date, sizeof(header.creation_date));
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
readstat/spss/readstat_sav_write.c:158:5: warning: ‘strncpy’ output may be truncated copying 8 bytes from a string of length 8 [-Wstringop-truncation]
     strncpy(header.creation_time, creation_time, sizeof(header.creation_time));
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/spss/readstat_zsav_compress.c -o readstat/spss/readstat_zsav_compress.o
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/spss/readstat_por_write.c -o readstat/spss/readstat_por_write.o
readstat/spss/readstat_por_write.c: In function ‘por_emit_header’:
readstat/spss/readstat_por_write.c:194:5: warning: ‘strncpy’ output truncated before terminating nul copying 20 bytes from a string of the same length [-Wstringop-truncation]
     strncpy(vanity[1], "ASCII SPSS PORT FILE", 20);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/spss/readstat_spss.c -o readstat/spss/readstat_spss.o
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/spss/readstat_zsav_write.c -o readstat/spss/readstat_zsav_write.o
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/spss/readstat_sav_parse.c -o readstat/spss/readstat_sav_parse.o
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/spss/readstat_por_parse.c -o readstat/spss/readstat_por_parse.o
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/stata/readstat_dta_read.c -o readstat/stata/readstat_dta_read.o
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/stata/readstat_dta.c -o readstat/stata/readstat_dta.o
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/stata/readstat_dta_parse_timestamp.c -o readstat/stata/readstat_dta_parse_timestamp.o
gcc-8  -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c readstat/stata/readstat_dta_write.c -o readstat/stata/readstat_dta_write.o
g++-8  -std=gnu++11 -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c DfReader.cpp -o DfReader.o
g++-8  -std=gnu++11 -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c DfWriter.cpp -o DfWriter.o
g++-8  -std=gnu++11 -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c haven_types.cpp -o haven_types.o
g++-8  -std=gnu++11 -I"/home/hornik/tmp/R/include" -DNDEBUG  -I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include" -I/usr/local/include  -Ireadstat -DHAVE_ZLIB -fpic  -g -O2 -Wall -pedantic -mtune=native -c RcppExports.cpp -o RcppExports.o
g++-8 -std=gnu++11 -shared -L/home/hornik/tmp/R/lib -Wl,-O1 -o haven.so tagged_na.o readstat/readstat_parser.o readstat/readstat_metadata.o readstat/readstat_io_unistd.o readstat/readstat_bits.o readstat/readstat_variable.o readstat/readstat_writer.o readstat/readstat_error.o readstat/readstat_convert.o readstat/CKHashTable.o readstat/readstat_malloc.o readstat/readstat_value.o readstat/sas/readstat_xport_write.o readstat/sas/readstat_sas7bcat_read.o readstat/sas/readstat_sas7bdat_write.o readstat/sas/readstat_sas7bcat_write.o readstat/sas/ieee.o readstat/sas/readstat_xport_read.o readstat/sas/readstat_sas.o readstat/sas/readstat_sas_rle.o readstat/sas/readstat_xport.o readstat/sas/readstat_sas7bdat_read.o readstat/spss/readstat_sav_compress.o readstat/spss/readstat_spss_parse.o readstat/spss/readstat_sav_read.o readstat/spss/readstat_por_read.o readstat/spss/readstat_sav.o readstat/spss/readstat_por.o readstat/spss/readstat_sav_parse_timestamp.o readstat/spss/readstat_zsav_read.o readstat/spss/readstat_sav_write.o readstat/spss/readstat_zsav_compress.o readstat/spss/readstat_por_write.o readstat/spss/readstat_spss.o readstat/spss/readstat_zsav_write.o readstat/spss/readstat_sav_parse.o readstat/spss/readstat_por_parse.o readstat/stata/readstat_dta_read.o readstat/stata/readstat_dta.o readstat/stata/readstat_dta_parse_timestamp.o readstat/stata/readstat_dta_write.o DfReader.o DfWriter.o haven_types.o RcppExports.o -lz -L/home/hornik/tmp/R/lib -lR
installing to /srv/hornik/tmp/CRAN/haven.Rcheck/haven/libs

Oh nope, that's not ./configure.

@hadley
Copy link
Contributor Author

hadley commented Oct 12, 2018

Should be GCC 8.2.0

@evanmiller
Copy link
Contributor

evanmiller commented Oct 12, 2018 via email

@QuLogic
Copy link

QuLogic commented May 17, 2019

If that's the case, why not use memcpy instead?

@evanmiller
Copy link
Contributor

strncpy fills the remainder of the destination with zeros, so memcpy would necessitate additional code changes (calloc or memset).

@hadley
Copy link
Contributor Author

hadley commented Jun 29, 2019

At the very end of https://developers.redhat.com/blog/2018/05/24/detecting-string-truncation-with-gcc-8/ it says:

GCC 8 has introduced a new attribute to decorate arrays and pointers with that need not be NUL-terminated. The name of the attribute is nonstring, and it is used by GCC to suppress select -Wformat-truncation instances where the missing NUL is intended. It is important to note that since character arrays that are not NUL-terminated are not valid arguments to functions that expect strings (such as strlen or strcpy), using nonstring arrays with such functions is diagnosed.

Would you accept a patch that decorated the pascal strings with nonstring?

@evanmiller
Copy link
Contributor

Fine with me, provided everything works with Clang too.

@hadley
Copy link
Contributor Author

hadley commented Jul 2, 2019

Before I do this, I just wanted to double-check that we definitely can't just switch to memcpy()? For pascal strings, you shouldn't be reading past the string length anyway, right?

It seems like it would be safe in both of the following two common cases:

    if (label && strlen(label)) {
        value_label->label_len = strlen(label);
        value_label->label = malloc(value_label->label_len);
        strncpy(value_label->label, label, value_label->label_len);
    }
...
    strncpy(header_start.file_label, writer->file_label, sizeof(header_start.file_label));

@evanmiller
Copy link
Contributor

As I stated earlier, memcpy will necessitate additional code changes to get the zero-fill behavior. It's not a big deal, but it will require a few more lines of code.

@hadley
Copy link
Contributor Author

hadley commented Jul 2, 2019

I just wanted to double check that it's necessary - as far as I can tell most uses of strncpy() appear to be copying into a buffer of exactly the right size.

@hadley
Copy link
Contributor Author

hadley commented Jul 2, 2019

i.e. (and I totally accept that I'm probably just being particularly dense) I can't see where the zero-fill behaviour is needed in the above code

@evanmiller
Copy link
Contributor

This line zero-fills header_start.file_label:

strncpy(header_start.file_label, writer->file_label, sizeof(header_start.file_label));

@hadley
Copy link
Contributor Author

hadley commented Jul 2, 2019

Ah got it. I'm still having problems replicating the compiler warnings locally, so haven't yet got to the point of trying out fixes 😞

@evanmiller
Copy link
Contributor

Try

0efc026

@hadley
Copy link
Contributor Author

hadley commented Jul 3, 2019

That's an improvement, but I still see a few:

In function ‘readstat_copy_label.isra.0’,
    inlined from ‘readstat_add_value_label’ at readstat/readstat_writer.c:94:5:
readstat/readstat_writer.c:82:9: warning: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation]
         strncpy(value_label->label, label, value_label->label_len);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
readstat/readstat_writer.c: In function ‘readstat_add_value_label’:
readstat/readstat_writer.c:80:34: note: length computed here
         value_label->label_len = strlen(label);
                                  ^~~~~~~~~~~~~
readstat/readstat_writer.c: In function ‘readstat_add_label_set’:
readstat/readstat_writer.c:300:5: warning: ‘strncpy’ specified bound 256 equals destination size [-Wstringop-truncation]
     strncpy(new_label_set->name, name, sizeof(new_label_set->name));
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
readstat/readstat_writer.c: In function ‘readstat_label_string_value’:
readstat/readstat_writer.c:355:9: warning: ‘strncpy’ output truncated before terminating nul copying as many bytesfrom a string as its length [-Wstringop-truncation]
         strncpy(new_value_label->string_key, value, new_value_label->string_key_len);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
readstat/readstat_writer.c:353:43: note: length computed here
         new_value_label->string_key_len = strlen(value);
                                           ^~~~~~~~~~~~~
readstat/sas/readstat_sas.c: In function ‘sas_write_header’:
readstat/sas/readstat_sas.c:284:5: warning: ‘strncpy’ output may be truncated copying 64 bytes from a string of length 99 [-Wstringop-truncation]
     strncpy(header_start.file_label, writer->file_label, sizeof(header_start.file_label));
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
readstat/sas/readstat_sas.c:337:5: warning: ‘strncpy’ output may be truncated copying 8 bytes from a string of length 31 [-Wstringop-truncation]
     strncpy(header_end.release, release, sizeof(header_end.release));
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
readstat/spss/readstat_sav_write.c: In function ‘sav_emit_header’:
readstat/spss/readstat_sav_write.c:156:5: warning: ‘strncpy’ output may be truncated copying 9 bytes from a stringof length 9 [-Wstringop-truncation]
     strncpy(header.creation_date, creation_date, sizeof(header.creation_date));
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
readstat/spss/readstat_sav_write.c:164:5: warning: ‘strncpy’ output may be truncated copying 8 bytes from a stringof length 8 [-Wstringop-truncation]
     strncpy(header.creation_time, creation_time, sizeof(header.creation_time));
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In function ‘sav_varnames_init’,
    inlined from ‘sav_begin_data.part.2’ at readstat/spss/readstat_sav_write.c:1320:32,
    inlined from ‘sav_begin_data’ at readstat/spss/readstat_sav_write.c:1314:25:
readstat/spss/readstat_sav_write.c:1296:9: warning: ‘strncpy’ output may be truncated copying 8 bytes from a string of length 299 [-Wstringop-truncation]
         strncpy(shortname, name, 8);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
gcc -I"/opt/R-devel/lib/R/include" -DNDEBUG  -I"/opt/R-devel/lib/R/library/Rcpp/include" -I/usr/local/include  -Ire
readstat/spss/readstat_por_write.c: In function ‘por_emit_header’:
readstat/spss/readstat_por_write.c:205:5: warning: ‘strncpy’ output truncated before terminating nul copying 20 bytes from a string of the same length [-Wstringop-truncation]
     strncpy(vanity[1], "ASCII SPSS PORT FILE", 20);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gcc -I"/opt/R-devel/lib/R/include" -DNDEBUG  -I"/opt/R-devel/lib/R/library/Rcpp/include" -I/usr/local/include  -Ire

You can see my (likely feeble!) efforts to fix the problem at tidyverse/haven#460 (I was trying to prototype on my embedded of readstat before I bothered you for more feedback; but it might be useful).

We also discovered that to see the full set of warnings that I'm getting from CRAN you need -O2

@evanmiller
Copy link
Contributor

Please try the referenced commit (dev branch, not master)

@hadley
Copy link
Contributor Author

hadley commented Jul 3, 2019

Oh shoot, I'm an idiot - sorry!

@hadley
Copy link
Contributor Author

hadley commented Jul 3, 2019

Now I only see one warning:

In function ‘sav_varnames_init’,
    inlined from ‘sav_begin_data.part.2’ at readstat/spss/readstat_sav_write.c:1320:32,
    inlined from ‘sav_begin_data’ at readstat/spss/readstat_sav_write.c:1314:25:
readstat/spss/readstat_sav_write.c:1296:9: warning: ‘strncpy’ output may be truncated copying 8 bytes from a string of length 299 [-Wstringop-truncation]
         strncpy(shortname, name, 8);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~

evanmiller added a commit that referenced this issue Jul 3, 2019
@evanmiller
Copy link
Contributor

Ok try 369e51a

@evanmiller
Copy link
Contributor

Well, that broke Travis. Here's another stab at it: 17e912b

@hadley
Copy link
Contributor Author

hadley commented Jul 4, 2019

That did it! Is this branch ok to use in the haven release? I'm trying to get something to CRAN today/tomorrow before I leave for a conference.

@evanmiller
Copy link
Contributor

It should be fine right now, but generally dev is where I break things and master always points to the latest stable release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants