From 4231e7de561e34d584f8a36e3e5663bd69291582 Mon Sep 17 00:00:00 2001 From: Alexander Blume Date: Wed, 26 Apr 2023 10:26:24 +0200 Subject: [PATCH] methCall: update the parsing of cigar string - replace calls to deprecated sprintf with snprintf Signed-off-by: Alexander Blume --- src/methCall.cpp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/methCall.cpp b/src/methCall.cpp index 06e1a41..9961e97 100644 --- a/src/methCall.cpp +++ b/src/methCall.cpp @@ -900,21 +900,15 @@ int process_bam ( std::string &input, // initialize buffers for sequence, qual and cigar string std::string seq, qual; std::vector cigar_buffer(len_cigar + 1); - - // initialize counter and cigar-buffer-storage - int i = 0; - int c; + // initialize counter + int i = 0; - // parse the first cigar operation - c = std::sprintf(cigar_buffer,"%i%c", bam_cigar_oplen(cigar_pointer[0]), bam_cigar_opchr(cigar_pointer[0])) ; - // if further operations remain, append them to cigar_buffer - if (len_cigar >= 2 ) { - for (i = 1; ((unsigned) i) < len_cigar; i++ ) { - char buffer [c]; - c = std::sprintf(buffer,"%i%c", bam_cigar_oplen(cigar_pointer[i]), bam_cigar_opchr(cigar_pointer[i])) ; - strcat(cigar_buffer,buffer); - } + // parse the cigar operations + for (i = 0; i < len_cigar; i++) + { + // place each operation as character into cigar_buffer + std::snprintf(&cigar_buffer[i], cigar_buffer.size(), "%i%c", bam_cigar_oplen(cigar_pointer[i]), bam_cigar_opchr(cigar_pointer[i])); } for (i = 0; i < len; i++ ) { qual += bam_get_qual(b)[i]+offset;}