[EMBOSS-BUG] bizarre behaviour of ajSeqGetUsa

pmr at ebi.ac.uk pmr at ebi.ac.uk
Sat Sep 18 10:15:30 UTC 2004

Dear Guy,

> I discovered something bizarre. To see it, try the following program under
> EMBOSS 2.9.0 :

>   ajFmtPrint("We have %S and %S\n", ajSeqGetUsa(seq1), ajSeqGetUsa(seq2));

> test sw:papa_carpa sw:tpa_human
> outputs
> We have sw-id:TPA_HUMAN and sw-id:TPA_HUMAN
> Where is sw:PAPA_CARPA gone ? I do not know whether this is a bug or a
> "feature", but it is surely counterintuituve behaviour.

It's a feature, but one that does need careful documentation.

ajSeqGetUsa returns a pointer to an AjPStr ... but that string has to
exist somewhere, and as the USA is not necessarily in the original AjPSeq
is makes one up. This leaves your second ajSeqGetUsa call overwriting the
string before the first one has been printed.

Any function returning a "const AjPStr" could, in thory, have such
effects. It depends though on whether the AjPStr is likely to change, or
whether it depends entirely on the input to the function. We should at
least mark such cases in the documentation.

Making a new string would cause a memory leak. The recommended solutions
would be:

1. split the ajFmtPrint statement into two
2. copy the ajSeqGetUsa result into a string, and clean it up

Our solutions could be (for a future release) populating a Usa attribute
of the AjPSeq and passing that back. As an AjPSeq attribute it would then
be cleaned up by the AjPSeq destructor. At present this attribute contains
the original USA but I see no reason not to "correct" it. The alternative
would involve writing a lot of extra documentation .... I think I prefer
the code fix.

Hpe this helps,


More information about the emboss-dev mailing list