Skip to content

Commit

Permalink
fastx: improve ugly 'fgets' hack to avoid compilation warnings.
Browse files Browse the repository at this point in the history
This change was already included in the previously released
version 0.0.13.2 (but I forgot to add it here).
Enables compiling with "-D_FORTIFY_SOURCE=2".

Solves github issue #1.
  • Loading branch information
agordon committed Nov 9, 2013
1 parent 09c3996 commit 0c78199
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/libfastx/fastx.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ int fastx_read_next_record(FASTX *pFASTX)
errx(1,"Internal error: pFASTX==NULL (%s:%d)", __FILE__,__LINE__);

pFASTX->input_line_number++;
if (fgets(pFASTX->input_sequence_id_prefix, MAX_SEQ_LINE_LENGTH, pFASTX->input) == NULL)
if (fgets(pFASTX->dummy_read_id_buffer, MAX_SEQ_LINE_LENGTH, pFASTX->input) == NULL)
return 0; //assume end-of-file, if we couldn't read the first line of the foursome

chomp(pFASTX->name);
Expand Down Expand Up @@ -367,7 +367,7 @@ int fastx_read_next_record(FASTX *pFASTX)

if (pFASTX->read_fastq) {
pFASTX->input_line_number++;
if (fgets(pFASTX->input_name2_prefix, MAX_SEQ_LINE_LENGTH, pFASTX->input) == NULL)
if (fgets(pFASTX->dummy_read_id2_buffer, MAX_SEQ_LINE_LENGTH, pFASTX->input) == NULL)
errx(1,"Failed to read complete record, missing 3rd line (name-2), on line %lld\n",
pFASTX->input_line_number);

Expand Down
18 changes: 14 additions & 4 deletions src/libfastx/fastx.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,23 @@ typedef enum {
typedef struct
{
/* Record data - common for FASTA/FASTQ */
char input_sequence_id_prefix[1]; //DON'T touch this - this hack will read the entire name into the variable 'name',
union {
struct {
char input_sequence_id_prefix[1]; //DON'T touch this - this hack will read the entire name into the variable 'name',
//leaving the prefix ('>' or '@') in 'input_sequence_id_name'.
char name[MAX_SEQ_LINE_LENGTH+1];
char name[MAX_SEQ_LINE_LENGTH+1];
};
char dummy_read_id_buffer[MAX_SEQ_LINE_LENGTH+2];
};
char nucleotides[MAX_SEQ_LINE_LENGTH+1];
/* Record data - only for FASTQ */
char input_name2_prefix[1]; //same hack as 'input_sequence_id_prefix'
char name2[MAX_SEQ_LINE_LENGTH+1];
union {
struct {
char input_name2_prefix[1]; //same hack as 'input_sequence_id_prefix'
char name2[MAX_SEQ_LINE_LENGTH+1];
};
char dummy_read_id2_buffer[MAX_SEQ_LINE_LENGTH+2];
};
int quality[MAX_SEQ_LINE_LENGTH+1]; //note: this is NOT ascii values, but numerical values
// numeric quality scores and ASCII quality scores
// are automatically converted to numbers (-15 to 93)
Expand Down

0 comments on commit 0c78199

Please sign in to comment.