From f002c02f4f7372e202bef7a7fa5a3f04a917c7e5 Mon Sep 17 00:00:00 2001 From: Niels De Graef Date: Wed, 16 Nov 2016 13:35:46 +0100 Subject: [PATCH] replace stopMemset() with clearString(). For all intents and purposes, string handling functions will make use of it in the same way. Otherwise it should be using memset() anyway. --- hmm_lib.c | 14 +++++++------- run_hmm.c | 6 +++--- util_lib.c | 11 +++-------- util_lib.h | 8 +++++++- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/hmm_lib.c b/hmm_lib.c index 5e8671d..99c39b1 100644 --- a/hmm_lib.c +++ b/hmm_lib.c @@ -792,13 +792,13 @@ void viterbi(HMM *hmm_ptr, char *O, char* output_buffer, char* aa_buffer, (vpath[t]==M1_STATE || vpath[t]==M4_STATE || vpath[t]==M1_STATE_1 || vpath[t]==M4_STATE_1)) { - stopMemset(dna, STRINGLEN); - stopMemset(dna1, STRINGLEN);// - stopMemset(dna_f, STRINGLEN);// - stopMemset(dna_f1, STRINGLEN);// - stopMemset(protein, STRINGLEN); - stopMemset(insert, STRINGLEN);// - stopMemset(c_delete, STRINGLEN);// + clearString(dna, STRINGLEN); + clearString(dna1, STRINGLEN); + clearString(dna_f, STRINGLEN); + clearString(dna_f1, STRINGLEN); + clearString(protein, STRINGLEN); + clearString(insert, STRINGLEN); + clearString(c_delete, STRINGLEN); insert_id = 0; delete_id = 0; diff --git a/run_hmm.c b/run_hmm.c index 4b2b7d2..e18322c 100644 --- a/run_hmm.c +++ b/run_hmm.c @@ -610,9 +610,9 @@ void writeAminoAcids(FILE* aa_outfile_fp, thread_data* td, unsigned int buffer) } //!! Why are we clearing dna and output buff? - stopMemset(td->output_buffer[buffer][j], STRINGLEN); - stopMemset(td->aa_buffer[buffer][j], STRINGLEN); - stopMemset(td->dna_buffer[buffer][j], STRINGLEN); + clearString(td->output_buffer[buffer][j], STRINGLEN); + clearString(td->aa_buffer[buffer][j], STRINGLEN); + clearString(td->dna_buffer[buffer][j], STRINGLEN); } } diff --git a/util_lib.c b/util_lib.c index 9a3e80d..435e148 100644 --- a/util_lib.c +++ b/util_lib.c @@ -488,12 +488,7 @@ void print_usage() { } -void stopMemset(char* ptr, int length) { - int i; - for(i=0; i 0) + str[0] = '\0'; } diff --git a/util_lib.h b/util_lib.h index adcbb9b..11097b5 100644 --- a/util_lib.h +++ b/util_lib.h @@ -39,6 +39,12 @@ QUEUE* deq(unsigned int which); void cutnpaste_q(QUEUE** dest, unsigned int which); -void stopMemset(char* ptr, int length); +/* + * Sets the string's first charachter to '\0', so string functions handle it + * like an empty string. + * + * NOTE: if you plan to use functions that use a given length, it's safer to use memset + */ +void clearString(char* str, int length); #endif