The mistake was that i expected printf to print a string but in reality passed a non string to it.
For Ansi-C I usually write a structure to encapsule strings.
typedef struct TString{
char buffer[2000];
}TString;
I tend to write:
void mistake( void ){
TString str;
TStrnig_Construct(&str);
prtinf( "%s", str );
TString_Destuct(&str);
}
This is hard to spot for me since it really looks like str is a string. In reality str is not a string but a structure. This error can manifest anywhere, especially if the content of the tructure is extended with other information (e.g. size_t size
).
I should have written:
void corrected( void ){
TString str;
TStrnig_Construct(&str);
prtinf( "%s", str.buffer );
TString_Destuct(&str);
}