Skip to content

Instantly share code, notes, and snippets.

@wch
Created March 19, 2019 17:15
Show Gist options
  • Save wch/255058e9639992a28573a3bcb9cdfcd4 to your computer and use it in GitHub Desktop.
Save wch/255058e9639992a28573a3bcb9cdfcd4 to your computer and use it in GitHub Desktop.
Commands for reproducing CRAN r-devel-linux-x86_64-debian-gcc compiler warnings with Docker
docker run --rm -ti rhub/debian-gcc-devel
echo -e "
#include <stdlib.h>
#include <string.h>
char* create_string(const char* value) {
// strlen doesn't count null terminator
int n = strlen(value) + 1;
char* str = (char *) malloc(n);
strncpy(str, value, n);
return str;
}" > create_string.c
gcc -O2 -Wall -c create_string.c -o create_string.o
# This will result in:
#
# root@45c98a6c18dc:/# gcc -O2 -Wall -c create_string.c -o create_string.o
# create_string.c: In function ‘create_string’:
# create_string.c:9:3: warning: ‘strncpy’ specified bound depends on the length of the source argument [-Wstringop-overflow=]
# strncpy(str, value, n);
# ^~~~~~~~~~~~~~~~~~~~~~
# create_string.c:7:11: note: length computed here
# int n = strlen(value) + 1;
# ^~~~~~~~~~~~~
# ====================================================================
#
# To reproduce a WARNING with R CMD check in the sass package, do the following
docker run --rm -ti debian:testing
apt-get update
apt-get install -y gcc vim r-base git
git clone https://github.com/rstudio/sass.git
cd sass
git checkout 6099440
cd ..
R -e "install.packages(c('knitr', 'rmarkdown', 'testthat'))"
# Edit Makeconf. For CFLAGS, add -O2 -Wall, and remove -D_FORTIFY_SOURCE=2
vim /usr/lib/R/etc/Makeconf
R CMD build --no-build-vignettes sass
R CMD check --no-tests --no-vignettes sass_0.1.1.tar.gz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment