Commit c7b8db6a by Celine Mercier

Replaced malloc+memset with calloc

parent 1dc4a3be
......@@ -63,17 +63,14 @@ byte_t* encode_seq_on_2_bits(const char* seq, int32_t length)
length_b = ceil((double) length / (double) 4.0);
seq_b = (byte_t*) malloc(length_b * sizeof(byte_t));
seq_b = (byte_t*) calloc(length_b, sizeof(byte_t));
if (seq_b == NULL)
{
obi_set_errno(OBI_MALLOC_ERROR); // TODO
obi_set_errno(OBI_MALLOC_ERROR);
obidebug(1, "\nError allocating memory for an encoded DNA sequence");
return NULL;
}
// Initialize all the bits to 0
memset(seq_b, 0, length_b);
for (i=0; i<length; i++)
{
// Shift of 2 to make place for new nucleotide
......@@ -99,7 +96,7 @@ byte_t* encode_seq_on_2_bits(const char* seq, int32_t length)
seq_b[i/4] |= NUC_T_2b;
break;
default:
obi_set_errno(OBI_ENCODE_ERROR); // TODO
obi_set_errno(OBI_ENCODE_ERROR);
obidebug(1, "\nInvalid nucleotide base when encoding (not [atgcATGC])");
return NULL;
}
......@@ -125,7 +122,7 @@ char* decode_seq_on_2_bits(byte_t* seq_b, int32_t length_seq)
seq = (char*) malloc((length_seq+1) * sizeof(char));
if (seq == NULL)
{
obi_set_errno(OBI_MALLOC_ERROR); // TODO
obi_set_errno(OBI_MALLOC_ERROR);
obidebug(1, "\nError allocating memory for a decoded DNA sequence");
return NULL;
}
......@@ -151,7 +148,7 @@ char* decode_seq_on_2_bits(byte_t* seq_b, int32_t length_seq)
seq[i] = 't';
break;
default:
obi_set_errno(OBI_DECODE_ERROR); // TODO
obi_set_errno(OBI_DECODE_ERROR);
obidebug(1, "\nInvalid nucleotide base when decoding");
return NULL;
}
......@@ -172,17 +169,14 @@ byte_t* encode_seq_on_4_bits(const char* seq, int32_t length)
length_b = ceil((double) length / (double) 2.0);
seq_b = (byte_t*) malloc(length_b * sizeof(byte_t));
seq_b = (byte_t*) calloc(length_b, sizeof(byte_t));
if (seq_b == NULL)
{
obi_set_errno(OBI_MALLOC_ERROR); // TODO
obi_set_errno(OBI_MALLOC_ERROR);
obidebug(1, "\nError allocating memory for an encoded DNA sequence");
return NULL;
}
// Initialize all the bits to 0
memset(seq_b, 0, length_b);
for (i=0; i<length; i++)
{
// Shift of 4 to make place for new nucleotide
......@@ -252,7 +246,7 @@ byte_t* encode_seq_on_4_bits(const char* seq, int32_t length)
seq_b[i/2] |= NUC_N_4b;
break;
default:
obi_set_errno(OBI_ENCODE_ERROR); // TODO
obi_set_errno(OBI_ENCODE_ERROR);
obidebug(1, "\nInvalid nucleotide base when encoding (not IUPAC)");
return NULL;
}
......@@ -278,7 +272,7 @@ char* decode_seq_on_4_bits(byte_t* seq_b, int32_t length_seq)
seq = (char*) malloc((length_seq+1) * sizeof(char));
if (seq == NULL)
{
obi_set_errno(OBI_MALLOC_ERROR); // TODO
obi_set_errno(OBI_MALLOC_ERROR);
obidebug(1, "\nError allocating memory for a decoded DNA sequence");
return NULL;
}
......@@ -337,7 +331,7 @@ char* decode_seq_on_4_bits(byte_t* seq_b, int32_t length_seq)
seq[i] = 'n';
break;
default:
obi_set_errno(OBI_DECODE_ERROR); // TODO
obi_set_errno(OBI_DECODE_ERROR);
obidebug(1, "\nInvalid nucleotide base when decoding");
return NULL;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment