Skip to content

Commit

Permalink
Merge pull request #482 from ycphs/snprintf_fix
Browse files Browse the repository at this point in the history
silence -Wformat warning
  • Loading branch information
JanMarvin authored Aug 8, 2024
2 parents ab2be82 + ae41308 commit d0c1bb9
Showing 1 changed file with 11 additions and 24 deletions.
35 changes: 11 additions & 24 deletions src/read_workbook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,12 +536,11 @@ SEXP read_workbook(IntegerVector cols_in,
CharacterVector col_names(nCols);
IntegerVector removeFlag;
int pos = 0;

// If we are told col_names exist take the first row and fill any gaps with X.i
if(hasColNames){

int row_1 = rows[0];
char name[6];

IntegerVector row1_inds = which_cpp(rows == row_1);
IntegerVector header_cols = cols[row1_inds];
Expand All @@ -550,24 +549,15 @@ SEXP read_workbook(IntegerVector cols_in,

// looping over each column
for(unsigned short i=0; i < nCols; i++){

std::string nm = "X" + std::to_string(i + 1);

if(missing_header[i]){ // a missing header element
snprintf(&(name[0]), sizeof(name), "X%hu", i+1);
// sprintf(&(name[0]), "X%u", i+1);
// snprintf(&(name[0]), sizeof(&(name[0])), "X%d", i+1);
// snprintf(&(name[0]), 10, "X%d", i+1);
col_names[i] = name;

}else{ // this is a header elements

col_names[i] = nm.c_str();
}else{ // this is a header elements

col_names[i] = v[pos];
if(col_names[i] == "NA"){
snprintf(&(name[0]), sizeof(name), "X%hu", i+1);

// sprintf(&(name[0]), "X%du", i+1);
// snprintf(&(name[0]), sizeof(&(name[0])), "X%d", i+1);
// snprintf(&(name[0]), 10, "X%d", i+1);
col_names[i] = name;
col_names[i] = nm.c_str();
}

pos++;
Expand Down Expand Up @@ -621,13 +611,10 @@ SEXP read_workbook(IntegerVector cols_in,


}else{ // else col_names is FALSE
char name[6];
for(int i =0; i < nCols; i++){
snprintf(&(name[0]), sizeof(name), "X%hu", i+1);

// snprintf(&(name[0]), sizeof(&(name[0])), "X%d", i+1);
// sprintf(&(name[0]), "X%u", i+1);
col_names[i] = name;
for(unsigned short i =0; i < nCols; i++){

std::string nm = "X" + std::to_string(i + 1);
col_names[i] = nm.c_str();
}
}

Expand Down

0 comments on commit d0c1bb9

Please sign in to comment.